Skip to content

Instantly share code, notes, and snippets.

@chrismademe
Last active June 8, 2016 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismademe/e482db23a961f7e628c45970be1e6a0f to your computer and use it in GitHub Desktop.
Save chrismademe/e482db23a961f7e628c45970be1e6a0f to your computer and use it in GitHub Desktop.
Get Products with a particular Tag (WooCommerce)
<?php
// Get tagged products
$featured_products = get_posts(array(
'posts_per_page' => 3,
'post_type' => 'product',
'product_tag' => 'featured',
'orderby' => 'date'
));
// Loop over them
foreach ( $featured_products as $product ):
$product = wc_get_product($product->ID); // Replace WP_Post object with WC_Product
?>
<div class="product"><?php echo $product->get_title(); // Do some stuff ?></div>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment