Created
January 11, 2019 12:23
-
-
Save felixkipyego/1deab213d4e8d7d6a22c22468cd4bd9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function woocommerce_featured_products_fix( $atts ) { | |
$attributes_fet = shortcode_atts( array( | |
'number' => '12' | |
), $atts ); | |
?> | |
<ul class="products"> | |
<?php | |
$args = array( | |
'post_type' => 'product', | |
'posts_per_page' => $attributes_fet['number'], | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'product_visibility', | |
'field' => 'name', | |
'terms' => 'featured', | |
), | |
), | |
); | |
$loop = new WP_Query( $args ); | |
if ( $loop->have_posts() ) { | |
while ( $loop->have_posts() ) : $loop->the_post(); | |
wc_get_template_part( 'content', 'product' ); | |
endwhile; | |
} else { | |
echo __( 'No products found' ); | |
} | |
wp_reset_postdata(); | |
?> | |
</ul> | |
<?php | |
} | |
add_shortcode( 'woo_softwareske_featured', 'woocommerce_featured_products_fix' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the shortcode by pasting the following in a text editor in WordPress;
[woo_softwareske_featured] or [woo_softwareske_featured number="6"]