[英]WooCommerce remove product from a category programmatically based on date creation
Is there a way of removing a WooCommerce product from a certain category after 30 days?有没有办法在 30 天后从某个类别中删除 WooCommerce 产品?
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.然后在 30 天后,我希望它自动从该类别中删除,因为它不再是新的。
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'?我有一些代码可以评估产品的年龄,但我真的不知道如何使用 rest.... 我是否将其添加到我的“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,
}
?>
Thanks谢谢
Try something like this: wp_remove_object_terms( $product_id, $cat_ids, 'product_cat' );
尝试这样的事情: wp_remove_object_terms( $product_id, $cat_ids, 'product_cat' );
From this StackOverflow page .从这个StackOverflow 页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.