Last active
May 1, 2023 12:38
-
-
Save Auke1810/8b9849685635b10e6b6a8ced86527a0b to your computer and use it in GitHub Desktop.
Fill in the custom_label_0 with new if the product is created within 10 day's from now.
This file contains 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
<?php | |
function product_old_new( $attributes, $feed_id, $product_id ) { | |
global $product; | |
// Get product creat | |
$product = wc_get_product( $product_id ); | |
$product_created = strtotime($product->get_date_created()); | |
// Calculate the date 10 days ago | |
// Change the number in strtotime('-10 days') to your need | |
$x_days_ago = strtotime('-10 days'); | |
if ($product_created >= $x_days_ago) { | |
// the product is newly created and not older than 10 day's ago | |
// Change custom_label_0 to the one you need or use an other attribute. | |
$attributes['custom_label_0'] = "new"; | |
}else{ | |
$attributes['custom_label_0'] = "old"; | |
} | |
// IMPORTANT! Always return the $attributes | |
return $attributes; | |
} | |
add_filter( 'wppfm_feed_item_value', 'product_old_new', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment