Created
February 25, 2023 20:11
-
-
Save devinsays/c3a2ece27943ea47ce140988bafbdaf9 to your computer and use it in GitHub Desktop.
Updates coupon data in the verification table for WooCommerce Coupon Restrictions
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 | |
/** | |
* 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