Skip to content

Instantly share code, notes, and snippets.

@Auke1810
Last active May 1, 2023 12:38
Show Gist options
  • Save Auke1810/8b9849685635b10e6b6a8ced86527a0b to your computer and use it in GitHub Desktop.
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.
<?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