Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLeanne D
4,550 PointsWooCommerce remove product category pragmatically
Is there a way of removing a WooCommerce product from a certain category after 30 days?
So when I add a new product, I check the 'whats-new' category. Then after 30 days, I would like that to automatically be removed from that category, as it's no longer new.
I have a bit of code that can assess how old the product is, but then I don't really know how to work the rest.... and do i add this in my 'content-product.php'?
<?php $product = wc_get_product(get_the_ID());
$newness_days = 30;
$created = strtotime( $product->get_date_created() );
if ( ( time() - ( 60 * 60 * 24 * $newness_days ) ) < $created ) {
// if is new do nothing
} else {
// it's old, remove 'whats-new' category
} ?>
Thanks