diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index 540baeabb5f..83f0838f643 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -259,9 +259,8 @@ function wc_cart_totals_coupon_label( $coupon, $echo = true ) { } /** - * Get a coupon value. + * Get coupon display HTML. * - * @access public * @param string $coupon */ function wc_cart_totals_coupon_html( $coupon ) { @@ -269,25 +268,16 @@ function wc_cart_totals_coupon_html( $coupon ) { $coupon = new WC_Coupon( $coupon ); } - $value = array(); - if ( $amount = WC()->cart->get_coupon_discount_amount( $coupon->get_code(), WC()->cart->display_cart_ex_tax ) ) { - $discount_html = '-' . wc_price( $amount ); - } else { - $discount_html = ''; + $discount_amount_html = '-' . wc_price( $amount ); + } elseif ( $coupon->get_free_shipping() ) { + $discount_amount_html = __( 'Free shipping coupon', 'woocommerce' ); } - $value[] = apply_filters( 'woocommerce_coupon_discount_amount_html', $discount_html, $coupon ); + $discount_amount_html = apply_filters( 'woocommerce_coupon_discount_amount_html', $discount_amount_html, $coupon ); + $coupon_html = $discount_amount_html . ' ' . __( '[Remove]', 'woocommerce' ) . ''; - if ( $coupon->get_free_shipping() ) { - $value[] = __( 'Free shipping coupon', 'woocommerce' ); - } - - // get rid of empty array elements - $value = array_filter( $value ); - $value = implode( ', ', $value ) . ' ' . __( '[Remove]', 'woocommerce' ) . ''; - - echo apply_filters( 'woocommerce_cart_totals_coupon_html', $value, $coupon ); + echo wp_kses_post( apply_filters( 'woocommerce_cart_totals_coupon_html', $coupon_html, $coupon, $discount_amount_html ) ); } /**