Created
November 8, 2023 18:19
-
-
Save braddalton/6754784eb12920b19e3f5df560d89be3 to your computer and use it in GitHub Desktop.
Random Free Product For Each Day in WooCommerce https://wpsites.net/?p=114123
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
// Schedule the function to run hourly | |
add_action('init', 'schedule_update_random_free_product'); | |
// Function to select and update a random free product | |
function update_random_free_product() { | |
$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', current_time('Y-m-d')); | |
} | |
} | |
// Hook the function to run when the scheduled event fires | |
add_action('update_random_free_product_event', 'update_random_free_product'); | |
function schedule_update_random_free_product() { | |
if (!wp_next_scheduled('update_random_free_product_event')) { | |
wp_schedule_event(current_time('timestamp'), 'hourly', 'update_random_free_product_event'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment