How to add an Availability date based on the current date for the items on backorder?>
When creating a feed for Google Merchant center that contains items on backorder, it’s mandatory to add an availability date as a required field in the feed. Not adding an availability date will disapprove those items. So, either you have to add a static availability date to the product, or you can add a dynamic date to the feed. Adding a static date isn’t the best choice as the date will expire after a certain time. So, adding a dynamic date based on the current data would be the best choice to avoid getting disapproved items in GMC.
This documentation will describe how you can add a dynamic availability date based on the current date using a small code snippet. Please, follow the below steps –
First, install and activate a code snippet plugin. We prefer Code Snippets.
Once the plugin is installed and activated, you should find the option on the admin menu bar.
Go to Snippets > Add new
Paste the below code snippet as shown on the screenshot, and save.
Here we have added +7 days which you can change to any number just by changing the number here – $availability_date = gmdate( ‘c’, strtotime( ‘+7 days’ ) );-
/**
* @param string $availability_date
* @param \WC_Product $product
* @param array $config Feed Configuration
*
* @return string
*/
function woo_feed_filter_product_availability_date_callback( $availability_date, $product, $config ) {
if ($product->is_on_backorder() ) {
$availability_date = gmdate( 'c', strtotime( '+7 days' ) );
}
return $availability_date;
}
add_filter( 'woo_feed_filter_product_availability_date', 'woo_feed_filter_product_availability_date_callback',10,3 );
Now, once we generate a feed with the availability date as shown here, a feed will be generated where the availability value date will be the date based on the current date.
NB: This code snippet will work only for items on Backorder and having an empty Availability Date field.