get_gallery_image_ids(); /* $has_back_image = $theme_options['ts_effect_product']; if( !is_array($prod_galleries) || ( is_array($prod_galleries) && count($prod_galleries) == 0 ) ){ $has_back_image = false; } if( wp_is_mobile() ){ $has_back_image = false; } */ $image_size = apply_filters('aspace_loop_product_thumbnail', 'woocommerce_thumbnail'); $dimensions = wc_get_image_size( $image_size ); echo '
'; $front_img_src = ''; $alt = ''; if( has_post_thumbnail( $product->get_id() ) ){ $post_thumbnail_id = get_post_thumbnail_id($product->get_id()); $image_obj = wp_get_attachment_image_src($post_thumbnail_id, $image_size, 0); if( isset($image_obj[0]) ){ $front_img_src = $image_obj[0]; } $alt = trim(strip_tags( get_post_meta($post_thumbnail_id, '_wp_attachment_image_alt', true) )); } echo ''.esc_attr($alt).''; echo '
'; } if ( ! function_exists( 'aspace_product_categories' ) ) { /** * Display Product Categories * Hooked into the `homepage` action in the homepage template * * @since 1.0.0 * @param array $args the product section args. * @return void */ function aspace_product_categories( $args ) { $args = apply_filters( 'aspace_product_categories_args', array( 'limit' => 3, 'columns' => 3, 'child_categories' => 0, 'orderby' => 'menu_order', 'title' => __( 'Shop by Category', 'aspace' ), ) ); $shortcode_content = aspace_do_shortcode( 'product_categories', apply_filters( 'aspace_product_categories_shortcode_args', array( 'number' => intval( $args['limit'] ), 'columns' => intval( $args['columns'] ), 'orderby' => esc_attr( $args['orderby'] ), 'parent' => esc_attr( $args['child_categories'] ), ) ) ); /** * Only display the section if the shortcode returns product categories */ if ( false !== strpos( $shortcode_content, 'product-category' ) ) { echo '
'; do_action( 'aspace_homepage_before_product_categories' ); echo '

' . wp_kses_post( $args['title'] ) . '

'; do_action( 'aspace_homepage_after_product_categories_title' ); echo $shortcode_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped do_action( 'aspace_homepage_after_product_categories' ); echo '
'; } } } if (!function_exists('adforest_get_woo_categories')) { function adforest_get_woo_categories($post_id = 0, $product_cat = 'product_cat', $args = array()) { $post_id = (int) $post_id; $defaults = array(); $args = wp_parse_args($args, $defaults); $product_categories = wp_get_object_terms($post_id, $product_cat, $args); $cats = array(); $html = ''; foreach ($product_categories as $c) { $cat = get_category($c); $html .= '' . $cat->name . ','; } $return_value = rtrim($html, ","); return $return_value; } } if (!function_exists('adforest_shopPriceDirection')) { function adforest_shopPriceDirection($price = '', $curreny = '') { global $adforest_theme; $price = ( isset($price) && $price != "") ? $price : 0; if (isset($adforest_theme['sb_price_direction']) && $adforest_theme['sb_price_direction'] == 'right') { $price = $price . $curreny; } else if (isset($adforest_theme['sb_price_direction']) && $adforest_theme['sb_price_direction'] == 'right_with_space') { $price = $price . " " . $curreny; } else if (isset($adforest_theme['sb_price_direction']) && $adforest_theme['sb_price_direction'] == 'left') { $price = $curreny . $price; } else if (isset($adforest_theme['sb_price_direction']) && $adforest_theme['sb_price_direction'] == 'left_with_space') { $price = $curreny . " " . $price; } else { $price = $curreny . $price; } return $price; } } if (!function_exists('adforest_get_woo_stars')) { function adforest_get_woo_stars($average = 0) { $starsHTML = ''; $ratting = round($average); for ($i = 1; $i <= 5; $i++) { if ($i <= $ratting) { $starsHTML .= ''; } else { $starsHTML .= ''; } } return $starsHTML; } } function adforest_get_product_type($product_id) { $cache_key = WC_Cache_Helper::get_cache_prefix('product_' . $product_id) . '_type_' . $product_id; $product_type = wp_cache_get($cache_key, 'products'); if ($product_type) { return $product_type; } $post_type = get_post_type($product_id); if ('product_variation' === $post_type) { $product_type = 'variation'; } elseif ('product' === $post_type) { $terms = get_the_terms($product_id, 'product_type'); $product_type = !empty($terms) ? sanitize_title(current($terms)->name) : 'simple'; } else { $product_type = false; } wp_cache_set($cache_key, $product_type, 'products'); return $product_type; } function get_aspace_woo_cat() { $taxonomy = 'product_cat'; $orderby = 'name'; $show_count = 0; // 1 for yes, 0 for no $pad_counts = 0; // 1 for yes, 0 for no $hierarchical = 1; // 1 for yes, 0 for no $title = ''; $empty = 0; $args = array( 'taxonomy' => $taxonomy, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title, 'hide_empty' => $empty ); $all_categories = get_categories( $args ); foreach ($all_categories as $cat) { if($cat->category_parent == 0) { $category_id = $cat->term_id; echo '
'. $cat->name .''; $args2 = array( 'taxonomy' => $taxonomy, 'child_of' => 0, 'parent' => $category_id, 'orderby' => $orderby, 'show_count' => $show_count, 'pad_counts' => $pad_counts, 'hierarchical' => $hierarchical, 'title_li' => $title, 'hide_empty' => $empty ); /* $sub_cats = get_categories( $args2 ); if($sub_cats) { foreach($sub_cats as $sub_category) { echo $sub_category->name ; } } */ // with link /* $sub_cats = get_categories( $args2 ); if($sub_cats) { foreach($sub_cats as $sub_category) { echo '
'. $sub_category->name .''; } } */ //with counter $sub_cats = get_categories( $args2 ); if($sub_cats) { foreach($sub_cats as $sub_category) { echo '
'. $sub_category->name .''; echo apply_filters( 'woocommerce_subcategory_count_html', ' ' . $sub_category->count . '', $category ); } } } } } function gon_template_loop_product_label2(){ global $product, $post; ?>
is_on_sale()) : ?> get_regular_price() && is_numeric($product->get_regular_price()) && $product->get_regular_price() !=0) { $percentage = round( ( ( $product->get_regular_price() - $product->get_price() ) / $product->get_regular_price() ) * 100 ); } if ($percentage && $percentage>0 && !$product->is_type( 'variable' )) { $sales_html = apply_filters( 'woocommerce_sale_flash', '- ' . $percentage . '%', $post, $product ); } else { $sales_html = apply_filters( 'woocommerce_sale_flash', '' . esc_html__( 'Sale!', 'aspace' ) . '', $post, $product ); } ?>
is_in_stock() ){ /* Sale label */ if( $product->is_on_sale() ){ if( $theme_options['ts_show_sale_label_as'] != false ){ if( $product->get_type() == 'variable' ){ $regular_price = $product->get_variation_regular_price('max'); $sale_price = $product->get_variation_sale_price('min'); } else{ $regular_price = $product->get_regular_price(); $sale_price = $product->get_price(); } if( $regular_price ){ if( $theme_options['ts_show_sale_label_as'] == 'number' ){ $_off_price = round($regular_price - $sale_price, wc_get_price_decimals()); $price_display = '-' . sprintf(get_woocommerce_price_format(), get_woocommerce_currency_symbol(), $_off_price); echo ''.$price_display.''; } if( $theme_options['ts_show_sale_label_as'] == 'percent' ){ $_off_percent = ( 1 - round($sale_price / $regular_price, 2) ) * 100; echo '-'.$_off_percent.'%'; } } } else{ echo ''.esc_html(stripslashes($theme_options['ts_product_sale_label_text'])).''; } } /* Hot label */ if( $product->is_featured() ){ echo ''.esc_html(stripslashes($theme_options['ts_product_feature_label_text'])).''; } } else{ /* Out of stock */ echo ''.esc_html(stripslashes($theme_options['ts_product_out_of_stock_label_text'])).''; } ?>
_wp_specialchars( get_post_field( 'post_title', $attachment_id ), ENT_QUOTES, 'UTF-8', true ), 'data-caption' => _wp_specialchars( get_post_field( 'post_excerpt', $attachment_id ), ENT_QUOTES, 'UTF-8', true ), 'data-src' => esc_url( $full_src[0] ), 'data-large_image' => esc_url( $full_src[0] ), 'data-large_image_width' => esc_attr( $full_src[1] ), 'data-large_image_height' => esc_attr( $full_src[2] ), 'class' => esc_attr( $main_image ? 'wp-post-image' : '' ), ), $attachment_id, $image_size, $main_image ) ); if($is_thumb){ return ''; }else{ return ''; } } // custom die handler function wpmu_get_custom_die_handler() { return 'wpmu_custom_css_on_wp_die'; } // hook the function add_filter('wp_die_handler', 'wpmu_get_custom_die_handler' ); // custom login for theme function wpmu_custom_css_on_wp_die($message, $title = '', $args = array() ) { ?> <?php echo $title ?>
ID; $product = wc_get_product($post_id); ?> " height="20px" alt="icon-aspace-cart"/> ID; $product = wc_get_product($post_id); ?>
is_in_stock() ) { $availability = esc_html__( 'Out of stock', 'aspace' ); } elseif ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) { $availability = esc_html__( 'Available on backorder', 'aspace' ); } elseif ( $product->managing_stock() ) { $availability = wc_format_stock_for_display( $product ); } else { $availability = ''; } if ( ! $product->is_in_stock() ) { $class = 'out-of-stock'; } elseif ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) { $class = 'available-on-backorder'; } else { $class = 'in-stock'; } return array( 'availability' => $availability, 'class' => $class ); } add_action('woocommerce_proceed_to_checkout', 'aspace_cart_continue_shopping_button', 20); function aspace_cart_continue_shopping_button(){ echo ''.esc_html__('Continue Shopping', 'aspace').''; } function get_shop_page() { $shop_page_url = get_permalink( wc_get_page_id( 'shop' ) ); echo $shop_page_url; } // get woocommerce version number function aspace_get_woo_version_number() { if ( WC()->version ) { return WC()->version; } // If get_plugins() isn't available, require it if ( ! function_exists( 'get_plugins' ) ) { require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } // Create the plugins folder and file variables $plugin_folder = get_plugins( '/' . 'woocommerce' ); $plugin_file = 'woocommerce.php'; // If the plugin version number is set, return it if ( isset( $plugin_folder[ $plugin_file ]['Version'] ) ) { return $plugin_folder[ $plugin_file ]['Version']; } else { // Otherwise return null return null; } } /* Cart & Checkout - Start */ function aspace_cart_version() { global $aspace_settings; $cart_ver = ( isset( $aspace_settings['cart-version'] ) && $aspace_settings['cart-version'] ) ? $aspace_settings['cart-version'] : 'v1'; return apply_filters( 'aspace_filter_cart_version', $cart_ver ); } add_action( 'init', 'aspace_wc_cart_page' ); function aspace_wc_cart_page() { global $aspace_settings; if ( aspace_cart_version() == 'v2' ) { remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' ); add_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display', 20 ); add_action( 'woocommerce_before_cart_totals', 'aspace_shipping_calculator', 1 ); } } function aspace_shipping_calculator() { if ( WC()->cart->needs_shipping() && WC()->cart->show_shipping() ) { do_action( 'woocommerce_cart_totals_before_shipping' ); wc_cart_totals_shipping_html(); do_action( 'woocommerce_cart_totals_after_shipping' ); } elseif ( WC()->cart->needs_shipping() ) { woocommerce_shipping_calculator(); } } /* add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' ); function woocommerce_custom_single_add_to_cart_text() { return __( 'Download', 'aspace' ); } */ // To change add to cart text on product archives(Collection) page /* add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_custom_product_add_to_cart_text' ); function woocommerce_custom_product_add_to_cart_text() { return __( 'Download', 'aspace' ); } */ /* add_action( 'woocommerce_template_loop_add_to_cart', 'aspace_template_loop_add_to_cart_args' ); function aspace_template_loop_add_to_cart_args() { return __( 'Download', 'aspace' ); } */ //remove price if zero add_filter( 'woocommerce_get_price_html','maybe_hide_price',10,2); function maybe_hide_price($price_html, $product){ if( $product->get_price() == 0 && !is_admin() ){ return 'Free'; //or return 'Any text' } return $price_html; } //work /* function add_to_cart_regular_button() { $product = get_product(get_the_ID()); echo ""; } */ // Mini cart widget buttons remove_action('woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10); remove_action('woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20); function my_woocommerce_widget_shopping_cart_button_view_cart() { echo '' . esc_html__('My Downloads Cart', 'aspace') . ''; } function my_woocommerce_widget_shopping_cart_proceed_to_checkout() { echo '' . esc_html__('Go To Checkout', 'aspace') . ''; } add_action('woocommerce_widget_shopping_cart_buttons', 'my_woocommerce_widget_shopping_cart_button_view_cart', 10); add_action('woocommerce_widget_shopping_cart_buttons', 'my_woocommerce_widget_shopping_cart_proceed_to_checkout', 20); // Mini cart widget buttons End add_action( 'woocommerce_product_options_general_product_data', 'hiding_and_set_product_settings' ); function hiding_and_set_product_settings(){ ## ==> Set HERE your targeted user role: $targeted_user_role = 'administrator'; // Getting the current user object $user = wp_get_current_user(); // getting the roles of current user $user_roles = $user->roles; if ( in_array($targeted_user_role, $user_roles) ){ ## CSS RULES ## (change the opacity to 0 after testing) // HERE Goes OUR CSS To hide 'virtual' and 'downloadable' checkboxes ?> 'attachment', // Only bring back attachments 'post_mime_type' => 'image', // Only bring back attachments that are images 'posts_per_page' => '-1', // get them all 'post_status' => 'inherit', // Attachments default to "inherit", rather than published. Use "inherit" or "all". ); $images = new WP_Query( $args ); if ( $images->have_posts() ) { while( $images->have_posts() ) { $images->the_post(); $post = array( 'post_title' => get_the_title(), 'post_excerpt' => get_the_excerpt(), 'post_type' => 'product', ); $post_id = wp_insert_post( $post ); update_post_meta( $post_id, '_thumbnail_id', get_the_ID() ); } set_transient( 'aspace_convert_images_to_products', $images ); } } } //add_action( 'admin_init', 'aspace_convert_images_to_products' );