File: /var/www/shoetique/wp-content/themes/north-wp/vc_templates/thb_product.php
<?php function thb_product( $atts, $content = null ) {
$atts = vc_map_get_attributes( 'thb_product', $atts );
extract( $atts );
global $product, $woocommerce;
$args = array();
if ($product_sort == "latest-products") {
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $item_count
);
} else if ($product_sort == "featured-products") {
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'meta_key' => '_featured',
'meta_value' => 'yes',
'posts_per_page' => $item_count
);
} else if ($product_sort == "top-rated") {
add_filter( 'posts_clauses', array( $woocommerce->query, 'order_by_rating_post_clauses' ) );
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $item_count
);
$args['meta_query'] = $woocommerce->query->get_meta_query();
} else if ($product_sort == "sale-products") {
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $item_count,
'meta_query' => array(
'relation' => 'OR',
array( // Simple products type
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
),
array( // Variable products type
'key' => '_min_variation_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
)
)
);
} else if ($product_sort == "by-category"){
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'product_cat' => $cat,
'posts_per_page' => $item_count
);
} else if ($product_sort == "by-id"){
$product_id_array = explode(',', $product_ids);
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'post__in' => $product_id_array
);
} else {
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $item_count,
'meta_key' => 'total_sales',
'orderby' => 'meta_value'
);
}
ob_start();
$products = new WP_Query( $args );
switch($columns) {
case 2:
$col = 'medium-6';
break;
case 3:
$col = 'medium-4';
break;
case 4:
$col = 'medium-3';
break;
case 6:
$col = 'medium-2';
break;
}
$catalog_mode = ot_get_option('shop_catalog_mode', 'off');
$shop_product_listing = ot_get_option('shop_product_listing', 'style1');
if ( $products->have_posts() ) { ?>
<?php if ($carousel == "yes") { ?>
<div class="carousel-container">
<div class="carousel products owl row" data-columns="<?php echo $columns; ?>" data-navigation="true">
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php $product = wc_get_product( $products->post->ID ); ?>
<article itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" <?php post_class("post small-6 $col columns ".$shop_product_listing); ?>>
<?php do_action( 'woocommerce_before_shop_loop_item' ); ?>
<?php
$image_html = "";
if ( has_post_thumbnail() ) {
$image_html = wp_get_attachment_image( get_post_thumbnail_id(), 'shop_catalog' );
}
?>
<?php if ($shop_product_listing == 'style1') { ?>
<figure class="fresco">
<?php do_action( 'thb_product_badge'); ?>
<?php echo $image_html; ?>
<div class="overlay"></div>
<div class="buttons">
<?php echo thb_wishlist_button(); ?>
<div class="post-title<?php if ($catalog_mode == 'on') { echo ' catalog-mode'; } ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
<?php if ($catalog_mode != 'on') { ?>
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
<?php } ?>
</div>
</figure>
<?php } else if ($shop_product_listing == 'style2') { ?>
<figure class="fresco">
<?php do_action( 'thb_product_badge'); ?>
<a href="<?php the_permalink(); ?>"><?php echo $image_html; ?></a>
</figure>
<div class="post-title<?php if ($catalog_mode == 'on') { echo ' catalog-mode'; } ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
<?php if ($catalog_mode != 'on') { ?>
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
<?php } ?>
<?php } ?>
</article><!-- end product -->
<?php endwhile; // end of the loop. ?>
</div>
</div>
<?php } else { ?>
<div class="products shortcode row" data-equal="article">
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php $product = wc_get_product( $products->post->ID ); ?>
<article itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" <?php post_class("post item small-6 $col columns ".$shop_product_listing); ?>>
<?php do_action( 'woocommerce_before_shop_loop_item' ); ?>
<?php
$image_html = "";
if ( has_post_thumbnail() ) {
$image_html = wp_get_attachment_image( get_post_thumbnail_id(), 'shop_catalog' );
}
?>
<?php if ($shop_product_listing == 'style1') { ?>
<figure class="fresco">
<?php do_action( 'thb_product_badge'); ?>
<?php echo $image_html; ?>
<div class="overlay"></div>
<div class="buttons">
<?php echo thb_wishlist_button(); ?>
<div class="post-title<?php if ($catalog_mode == 'on') { echo ' catalog-mode'; } ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
<?php if ($catalog_mode != 'on') { ?>
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
<?php } ?>
</div>
</figure>
<?php } else if ($shop_product_listing == 'style2') { ?>
<figure class="fresco">
<?php do_action( 'thb_product_badge'); ?>
<a href="<?php the_permalink(); ?>"><?php echo $image_html; ?></a>
</figure>
<div class="post-title<?php if ($catalog_mode == 'on') { echo ' catalog-mode'; } ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
<?php if ($catalog_mode != 'on') { ?>
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
<?php } ?>
<?php } ?>
</article><!-- end product -->
<?php endwhile; // end of the loop. ?>
</div>
<?php } ?>
<?php }
$out = ob_get_contents();
if (ob_get_contents()) ob_end_clean();
wp_reset_query();
wp_reset_postdata();
remove_filter( 'posts_clauses', array( $woocommerce->query, 'order_by_rating_post_clauses' ) );
return $out;
}
add_shortcode('thb_product', 'thb_product');