Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created November 9, 2023 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save braddalton/bbb0d054ad757708d68bc5010f1b6253 to your computer and use it in GitHub Desktop.
Save braddalton/bbb0d054ad757708d68bc5010f1b6253 to your computer and use it in GitHub Desktop.
Daily Random Free Product for WooCommerce Changes The Price to Zero for 1 Day Only. Full Code https://wpsites.net/?p=114123
add_action('init', 'assign_random_free_product');
function assign_random_free_product() {
$today = date('Y-m-d');
$assigned_product_date = get_option('random_free_product_date');
if ( $today != $assigned_product_date ) {
$random_product_id = get_random_free_product();
if ( $random_product_id ) {
update_option('random_free_product_id', $random_product_id);
update_option('random_free_product_date', $today);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment