term_id, 'thumbnail_id', true ); if(isset($thumbnail_id) && !empty($thumbnail_id)){ $output .= wp_get_attachment_image( $thumbnail_id, 'shop_catalog', false, array('class'=>'scale-with-grid' ) ); }else{ $output .= wc_placeholder_img(); } } return $output; } public static function get_woo_cat_title($attr, $cat){ $output = ''; if($attr['title'] == 1){ $output .= '<'.$attr['title_tag'].' class="woocommerce-loop-category__title">'.$cat->name; if(isset($attr['count']) && $attr['count'] == 1){ $output .= '('.$cat->count.')'; } $output .= ''; } return $output; } public static function get_woo_product_title($product, $attr = false){ remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10); $output = '
'; ob_start(); do_action('woocommerce_before_shop_loop_item_title'); $output .= ob_get_clean(); $output .= '<'.$attr['title_tag'].' class="title">'.get_the_title($product->get_id()).''; if ( wc_review_ratings_enabled() ) { $output .= wc_get_rating_html( $product->get_average_rating() ); } $output .= '
'; if( has_action('woocommerce_after_shop_loop_item_title') ){ ob_start(); echo '
'; do_action('woocommerce_after_shop_loop_item_title'); echo '
'; $output .= ob_get_clean(); } return $output; } public static function sample_item($type){ $post = false; $posts = get_posts( array('post_type' => $type, 'numberposts' => 1, 'orderby' => 'ID', 'order' => 'ASC' ) ); if( isset($posts[0]) && count($posts) > 0 ){ $post = $posts[0]; } return $post; } public static function get_woo_product_image($product, $attr = false){ $wishlist_position = mfn_opts_get('shop-wishlist-position'); $is_translatable = mfn_opts_get('translate'); $translate['translate-add-to-cart'] = $is_translatable ? mfn_opts_get('translate-add-to-cart', 'Add to cart') : __('Add to cart', 'woocommerce'); $translate['translate-view-product'] = $is_translatable ? mfn_opts_get('translate-view-product', 'View product') : __('View product', 'woocommerce'); $translate['translate-add-to-wishlist'] = $is_translatable ? mfn_opts_get('translate-add-to-wishlist', 'Add to wishlist') : __('Add to wishlist', 'betheme'); // ! betheme $translate['translate-if-preview'] = $is_translatable ? mfn_opts_get('translate-if-preview', 'Preview') : __('Preview', 'woocommerce'); // output ----- $output = '
'; $shop_images = mfn_opts_get( 'shop-images' ); if( 'plugin' == $shop_images ){ $output .= ''; remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10); ob_start(); do_action( 'woocommerce_before_shop_loop_item_title' ); $output .= ob_get_clean(); $output .= ''; } else { $output .= '
'; if( mfn_opts_get('shop-wishlist') && isset($wishlist_position[1]) ){ $output .= ''; } ob_start(); wc_get_template( 'single-product/sale-flash.php'); do_action('mfn_product_image'); $output .= ob_get_clean(); // secondary image on hover $secondary_image_id = false; if( 'secondary' == $shop_images ){ if( $attachment_ids = $product->get_gallery_image_ids() ) { if( isset( $attachment_ids['0'] ) ){ $secondary_image_id = $attachment_ids['0']; } } } $output .= '
'; $output .= ''; $output .= '
'; $output .= woocommerce_get_product_thumbnail(); if( $secondary_image_id ){ $output .= wp_get_attachment_image( $secondary_image_id, 'shop_catalog', '', $attr = array( 'class' => 'image-secondary scale-with-grid' ) ); } $output .= '
'; $output .= ''; $output .= '
'; if( ! $product->is_in_stock() && $soldout = mfn_opts_get( 'shop-soldout' ) ){ $output .= '

'. $soldout .'

'; } $output .= ''; $output .= '
'; } $output .= '
'; return $output; } public static function get_woo_product_price($product, $attr = false){ /*ob_start(); mfn_display_custom_attributes($product->get_id()); $output = ob_get_clean();*/ $output = ''; if( !empty($product->get_price_html()) ){ $output .= '
'; $output .= '

'.$product->get_price_html().'

'; $output .= '
'; } return $output; } public static function get_woo_product_description($product, $attr = false){ $output = ''; if( get_the_excerpt($product->get_id()) && !empty($attr['description']) ){ $output .= '
'; $output .= '

'. do_shortcode( get_the_excerpt($product->get_id()) ) .'

'; $output .= '
'; } return $output; } public static function get_woo_product_button($product, $attr = false){ $classes = ''; if( $attr && (empty($attr['button']) || $attr['button'] == 0) ) return; $product->is_purchasable() ? $classes .= 'add_to_cart_button' : null; $product->supports( 'ajax_add_to_cart' ) ? $classes .= ' ajax_add_to_cart' : null; $output = '
'; $output .= apply_filters( 'woocommerce_loop_add_to_cart_link', sprintf( '%s', esc_url( $product->add_to_cart_url() ), esc_attr( $product->get_id() ), esc_attr( $product->get_sku() ), $classes, esc_attr( $product->get_type() ), esc_html( $product->add_to_cart_text() ) ), $product ); $wishlist = mfn_opts_get('shop-wishlist'); $wishlist_position = mfn_opts_get('shop-wishlist-position'); if( $wishlist && isset($wishlist_position[0]) && is_array($wishlist_position) && in_array(0, $wishlist_position)){ $output .= ''; } $output .= '
'; return $output; } public static function sample_products_loop($attr) { $sl_arr = array( 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => !empty($attr['products']) ? $attr['products'] : 8, ); if( get_option('woocommerce_hide_out_of_stock_items') && get_option('woocommerce_hide_out_of_stock_items') == 'yes' ) { $sl_arr['meta_query'] = array( array( 'key' => '_stock_status', 'value' => 'instock' ), ); } if( !empty($attr['ordering']) ){ switch ($attr['ordering']) { case 'price': $sl_arr['meta_key'] = '_price'; $sl_arr['orderby'] = 'meta_value_num'; $sl_arr['order'] = 'ASC'; break; case 'price-desc': $sl_arr['meta_key'] = '_price'; $sl_arr['orderby'] = 'meta_value_num'; $sl_arr['order'] = 'DESC'; break; case 'date': $sl_arr['orderby'] = 'post_date'; $sl_arr['order'] = 'DESC'; break; case 'popularity': $sl_arr['meta_key'] = 'total_sales'; $sl_arr['orderby'] = 'meta_value_num'; $sl_arr['order'] = 'DESC'; break; case 'rating': $sl_arr['meta_key'] = '_wc_average_rating'; $sl_arr['orderby'] = 'meta_value_num'; $sl_arr['order'] = 'DESC'; break; default: $sl_arr['orderby'] = 'menu_order'; $sl_arr['order'] = 'ASC'; break; } } $sample_loop = new WP_Query( $sl_arr ); return $sample_loop; } public static function productslist($product, $attr, $classes) { $order = str_replace(' ', '', $attr['order']); $order_arr = explode(',', $order); // if ( empty( $product ) || ! $product->is_visible() ) return; $output = '
  • '; ob_start(); echo '
    '; do_action('woocommerce_before_shop_loop_item'); echo '
    '; $output .= ob_get_clean(); if( isset($order_arr) && is_iterable($order_arr) ) { foreach( $order_arr as $el ) { if( ! isset( $attr[$el] ) || ( isset($attr[$el] ) && $attr[$el] ) ) { $fun_name = 'get_woo_product_'.$el; if( method_exists('Mfn_Builder_Woo_Helper', $fun_name) ){ $output .= self::$fun_name($product, $attr); } } } } ob_start(); echo '
    '; do_action('woocommerce_after_shop_loop_item'); echo '
    '; $output .= ob_get_clean(); $output .= '
  • '; return $output; } public static function getDiscount($product) { $percent = 0; if( $product->is_type('variable') ){ $percentages = array(); $prices = $product->get_variation_prices(); foreach( $prices['price'] as $key => $price ){ if( $prices['regular_price'][$key] !== $price ){ $percentages[] = round(100 - ($prices['sale_price'][$key] / $prices['regular_price'][$key] * 100)); } } $percent = round(max($percentages)); }elseif($product->get_regular_price() && $product->get_sale_price()){ $percent = round( (1 - ($product->get_sale_price() / $product->get_regular_price()))*100); } return $percent.'%'; } }