Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Last active September 21, 2019 16:12
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 EricBusch/7373a3aac5ee77e5ab341858f5292890 to your computer and use it in GitHub Desktop.
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.
<?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