Use wc_format_coupon_code when handling posted values
wc_clean and other functions strip characters - using wc_format_coupon_code keeps it consistent with post_title formatting.
This commit is contained in:
parent
96efb7a93b
commit
e8aecdb824
|
@ -547,10 +547,10 @@ class WC_Form_Handler {
|
|||
$nonce_value = wc_get_var( $_REQUEST['woocommerce-cart-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // @codingStandardsIgnoreLine.
|
||||
|
||||
if ( ! empty( $_POST['apply_coupon'] ) && ! empty( $_POST['coupon_code'] ) ) {
|
||||
WC()->cart->add_discount( sanitize_text_field( wp_unslash( $_POST['coupon_code'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
|
||||
WC()->cart->add_discount( wc_format_coupon_code( wp_unslash( $_POST['coupon_code'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
|
||||
} elseif ( isset( $_GET['remove_coupon'] ) ) {
|
||||
WC()->cart->remove_coupon( wc_clean( wp_unslash( $_GET['remove_coupon'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
|
||||
WC()->cart->remove_coupon( wc_format_coupon_code( urldecode( wp_unslash( $_GET['remove_coupon'] ) ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
|
||||
} elseif ( ! empty( $_GET['remove_item'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-cart' ) ) {
|
||||
$cart_item_key = sanitize_text_field( wp_unslash( $_GET['remove_item'] ) );
|
||||
|
|
|
@ -47,7 +47,7 @@ class WC_Order_Item_Coupon extends WC_Order_Item {
|
|||
* @param string $value Coupon code.
|
||||
*/
|
||||
public function set_code( $value ) {
|
||||
$this->set_prop( 'code', wc_clean( $value ) );
|
||||
$this->set_prop( 'code', wc_format_coupon_code( $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue