Compatibility with WooCommerce Free Gift Coupons
-
Hi, I’m the author of WooCommerce Free Gift Coupons and a customer came to me asking about compatibility with your plugin. My plugin saves some custom meta, but I believe there are 2 barriers to generating a Free Gift style coupon.
1. My admin coupon data is an array of arrays. My
$_POST
data looks like:array ( 10 => array ( 'quantity' => '1' ) );
This throws a notice in step 2:
[19-Apr-2021 17:10:52 UTC] PHP Notice: Array to string conversion in public\wp-includes\formatting.php on line 1098 [19-Apr-2021 17:10:52 UTC] PHP Stack trace: [19-Apr-2021 17:10:52 UTC] PHP 1. {main}() public\wp-admin\admin.php:0 [19-Apr-2021 17:10:52 UTC] PHP 2. do_action() public\wp-admin\admin.php:259 [19-Apr-2021 17:10:52 UTC] PHP 3. WP_Hook->do_action() public\wp-includes\plugin.php:484 [19-Apr-2021 17:10:52 UTC] PHP 4. WP_Hook->apply_filters() public\wp-includes\class-wp-hook.php:316 [19-Apr-2021 17:10:52 UTC] PHP 5. WCCG_Admin->coupon_generator_callback() public\wp-includes\class-wp-hook.php:292 [19-Apr-2021 17:10:52 UTC] PHP 6. WCCG_Generator->output_step() public\wp-content\plugins\coupon-generator-for-woocommerce\includes\admin\class-wccg-admin.php:114 [19-Apr-2021 17:10:52 UTC] PHP 7. WCCG_Generator->generator_options_handler() public\wp-content\plugins\coupon-generator-for-woocommerce\includes\admin\class-wccg-generator.php:105 [19-Apr-2021 17:10:52 UTC] PHP 8. require_once() public\wp-content\plugins\coupon-generator-for-woocommerce\includes\admin\class-wccg-generator.php:148 [19-Apr-2021 17:10:52 UTC] PHP 9. esc_attr() public\wp-content\plugins\coupon-generator-for-woocommerce\includes\admin\views\html-coupon-generator-step-2.php:68 [19-Apr-2021 17:10:52 UTC] PHP 10. wp_check_invalid_utf8() public\wp-includes\formatting.php:4504
which I believe is coming from attempting to escape the arrays:
if ( is_array( $val ) ) : foreach ( $val as $inner_val ) : ?><input type="hidden" name="<?php echo esc_attr( $key ); ?>[]" value="<?php echo esc_attr( $inner_val ); ?>" /><?php endforeach; else :
Barrier 2
Though the meta undergoes some more processing when saved. It appears you’re using
$wpdb
to insert new coupons instead of using WooCommerce’s CRUD. Even when I dabble in using the Woo CRUD I’m running into some issues with the data not being in$_POST
like my plugin currently expects. That may require a tweak on my end… but that’s to be determined if we’re interested in pursuing any compatibility.cheers!
- The topic ‘Compatibility with WooCommerce Free Gift Coupons’ is closed to new replies.