diff --git a/includes/Admin.php b/includes/Admin.php index f8f4d963a..2005c67bf 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -1610,7 +1610,7 @@ public function save_product_variation_edit_fields( $variation_id, $index ) { } // ALWAYS save Facebook field data (this fixes the PR #2931 breaking change) - $posted_param = 'variable_' . \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION; + $posted_param = 'variable_' . \WC_Facebookcommerce_Integration::FB_PRODUCT_DESCRIPTION; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Intentionally getting raw value to apply different sanitization methods below $description_raw = isset( $_POST[ $posted_param ][ $index ] ) ? wp_unslash( $_POST[ $posted_param ][ $index ] ) : null; diff --git a/includes/Checkout.php b/includes/Checkout.php index 4c940b2a5..749cc556b 100644 --- a/includes/Checkout.php +++ b/includes/Checkout.php @@ -147,7 +147,27 @@ public function load_checkout_permalink_template( $template ) { $coupon_code = get_query_var( 'coupon' ); if ( $coupon_code ) { - WC()->cart->apply_coupon( sanitize_text_field( $coupon_code ) ); + $coupon_code_sanitized = sanitize_text_field( $coupon_code ); + WC()->cart->apply_coupon( $coupon_code_sanitized ); + + if ( ! in_array( $coupon_code_sanitized, WC()->cart->get_applied_coupons(), true ) ) { + $error_message = sprintf( + 'Failed to apply coupon: %s', + $coupon_code_sanitized + ); + + \WC_Facebookcommerce_Utils::log_to_meta( + $error_message, + array( + 'flow_name' => 'checkout', + 'flow_step' => 'apply_coupon', + 'extra_data' => [ + 'coupon_param' => $coupon_code, + 'coupon_code' => $coupon_code_sanitized, + ], + ) + ); + } } $checkout_url = wc_get_checkout_url();