admin管理员组文章数量:1289831
I have a code that set "new" tag for products. I want to set that tag for products that have less than 14 days. I used for call the function add_action('init', 'name_fct');
, but I get an error, I tried with add_action('wp_enqueue_scripts', 'name_fct');
, but doesn't work. Please help me to develop my code to work. My code is:
SOLVED THANK YOU JACOB
function display_new_loop_woocommerce() {
global $product;
global $datetime_created;
global $timestamp_created;
global $datetime_now;
global $timestamp_now;
$datetime_now = new WC_DateTime();
$timestamp_now = $datetime_now->getTimestamp();
$args = array(
'post_type' => 'product', // your product post type
'posts_per_page' => - 1,
);
$posts = get_posts($args);
foreach ($posts as $post):
setup_postdata($post);
$product = new WC_Product($post->ID);
$datetime_created = $product->get_date_created();
$timestamp_created = $datetime_created->getTimestamp();
$time_delta = $timestamp_now - $timestamp_created;
$sixty_days = 14 * 24 * 60 * 60;
if ( $time_delta < $sixty_days ) {
if( ! has_term( '', 'product_tag', $post->ID ) ) :
wp_set_object_terms($post->ID, array('nou'), 'product_tag');
endif;
} else {
if( has_term( '', 'product_tag', $post->ID ) ) :
wp_remove_object_terms($post->ID, array('nou'), 'product_tag');
endif;
}
wp_reset_postdata();
endforeach;
}
本文标签: woocommerce offtopicSOLVEDaddaction() for productgtgetdatecreated
版权声明:本文标题:woocommerce offtopic - SOLVED - add_action() for $product->get_date_created 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741474335a2380791.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论