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 .= ''.$attr['title_tag'].'>';
}
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()).''.$attr['title_tag'].'>';
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 = '';
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 = '';
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.'%';
}
}