Fatal error creating coupon programmatically
-
When creating a coupon programmatically i get this error:
[18-Feb-2023 17:54:37 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to Automattic\WooCommerce\GoogleListingsAndAds\Coupon\SyncerHooks::Automattic\WooCommerce\GoogleListingsAndAds\Coupon\{closure}() must be of the type int, object given, called in /home/XXXXX/public_html/wp-includes/class-wp-hook.php on line 308 and defined in /home/XXXXX/public_html/wp-content/plugins/google-listings-and-ads/src/Coupon/SyncerHooks.php:107 Stack trace: #0 /home/XXXXX/public_html/wp-includes/class-wp-hook.php(308): Automattic\WooCommerce\GoogleListingsAndAds\Coupon\SyncerHooks->Automattic\WooCommerce\GoogleListingsAndAds\Coupon\{closure}(Object(WP_Error), Object(WC_Coupon)) #1 /home/XXXXX/public_html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array) #2 /home/XXXXX/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /home/XXXXX/public_html/wp-content/plugins/woocommerce/includes/data-stores/class-wc-coupon-data-store-cpt.php(99): do_action('woocommerce_new...', Object(WP_Error), Object(WC_Coupon)) #4 /home/XXXXX/public_h in /home/XXXXX/public_html/wp-content/plugins/google-listings-and-ads/src/Coupon/SyncerHooks.php on line 107
Coupon is created with the following code:
$coupon = new WC_Coupon(); $coupon->set_code( 'ABC-123' ); $coupon->set_description( 'My coupon description' ); $coupon->set_discount_type( 'percent' ); $coupon->set_amount( 10 ); $coupon->set_individual_use( true ); $coupon->set_usage_limit( 1 ); $coupon->set_usage_limit_per_user( 1 ); $coupon->set_limit_usage_to_x_items( 0 ); $coupon->set_free_shipping( false ); $coupon->set_email_restrictions( '[email protected]' ); $coupon->set_date_expires( '2023-12-31' ); $coupon->set_minimum_amount( 100 ); $coupon->save();
I was using this with no problems until i installed GoogleListingsAndAds. Disabing the plugin allows my function to execute and the coupon to be created.
Any thoughts?
[EDIT]
I’m doing this in a script outside the normal WP structure, and including “wp-blog-header.php”, “wp-config.php”, and “wp-load.php” in the begining of that script. Using similar code in my FUNCTIONS.PHP file i get no errors. What am i missing?!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Fatal error creating coupon programmatically’ is closed to new replies.