Skip to content

Instantly share code, notes, and snippets.

@devinsays
Created February 25, 2023 20:11
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 devinsays/c3a2ece27943ea47ce140988bafbdaf9 to your computer and use it in GitHub Desktop.
Save devinsays/c3a2ece27943ea47ce140988bafbdaf9 to your computer and use it in GitHub Desktop.
Updates coupon data in the verification table for WooCommerce Coupon Restrictions
<?php
/**
* Workaround to load historic data if WP CLI is not installed.
* Update the $code variable to match the coupon code you want to update.
*
* This code can be loaded in a custom plugin or in your theme's functions.php file.
*
* A transient is used to prevent the data from being updated more than once,
* but this code should be removed as soon as it has run and the table is updated.
*/
function add_order_data_for_coupon() {
$code = 'coupon_code';
$transient_key = $code . '_data_updated';
$updated = get_transient( $transient_key, 0 );
if ( ! $updated ) {
\WC_Coupon_Restrictions_Table::add_order_data_for_coupon( $code );
set_transient( $transient_key, 1, 60 * 60 * 24 );
}
}
add_action( 'init', 'add_order_data_for_coupon', 1000 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment