Merge pull request #13687 from woocommerce/fix-13674

Cleanup of wc_cart_totals_coupon_html
This commit is contained in:
Claudio Sanches 2017-03-21 10:23:17 -03:00 committed by GitHub
commit f6d7e52e06
1 changed files with 7 additions and 17 deletions

View File

@ -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 . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', urlencode( $coupon->get_code() ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]', 'woocommerce' ) . '</a>';
if ( $coupon->get_free_shipping() ) {
$value[] = __( 'Free shipping coupon', 'woocommerce' );
}
// get rid of empty array elements
$value = array_filter( $value );
$value = implode( ', ', $value ) . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', urlencode( $coupon->get_code() ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]', 'woocommerce' ) . '</a>';
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 ) );
}
/**