Last active
September 21, 2019 16:12
-
-
Save EricBusch/7373a3aac5ee77e5ab341858f5292890 to your computer and use it in GitHub Desktop.
This code auto updates WooCommerce's product lookup tables every hour. Change the HOUR_IN_SECONDS to some other time CONSTANT to adjust the schedule.
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 mycode_auto_update_product_lookup_table_schedules( $array ) { | |
$array['mycode_update_lookup_table_schedule'] = [ | |
'interval' => HOUR_IN_SECONDS, | |
'display' => __( 'MyCode Update Product Lookup Table Cron Schedule', 'mycode' ), | |
]; | |
return $array; | |
} | |
add_filter( 'cron_schedules', 'mycode_auto_update_product_lookup_table_schedules' ); | |
if ( ! wp_next_scheduled( 'mycode_trigger_lookup_table_update' ) ) { | |
wp_schedule_event( time(), 'mycode_update_lookup_table_schedule', 'mycode_trigger_lookup_table_update' ); | |
} | |
function mycode_wc_update_product_lookup_tables() { | |
require_once dirname( WC_PLUGIN_FILE ) . '/' . 'includes/wc-product-functions.php'; | |
if ( ! function_exists( 'wc_update_product_lookup_tables_is_running' ) ) { | |
return; | |
} | |
if ( ! function_exists( 'wc_update_product_lookup_tables' ) ) { | |
return; | |
} | |
if ( wc_update_product_lookup_tables_is_running() ) { | |
return; | |
} | |
wc_update_product_lookup_tables(); | |
} | |
add_action( 'mycode_trigger_lookup_table_update', 'mycode_wc_update_product_lookup_tables' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment