wc_cart_totals_coupon_html

Get coupon display HTML.

Description

wc_cart_totals_coupon_html( (string) $coupon ); 

Parameters (1)

0. $coupon (string)
The coupon.

Usage

  1. if ( !function_exists( 'wc_cart_totals_coupon_html' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-cart-functions.php'; 
  3.  
  4. // The coupon. 
  5. $coupon = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_cart_totals_coupon_html($coupon); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-cart-functions.php  
  1. function wc_cart_totals_coupon_html( $coupon ) { 
  2. if ( is_string( $coupon ) ) { 
  3. $coupon = new WC_Coupon( $coupon ); 
  4.  
  5. $discount_amount_html = ''; 
  6.  
  7. if ( $amount = WC()->cart->get_coupon_discount_amount( $coupon->get_code(), WC()->cart->display_cart_ex_tax ) ) { 
  8. $discount_amount_html = '-' . wc_price( $amount ); 
  9. } elseif ( $coupon->get_free_shipping() ) { 
  10. $discount_amount_html = __( 'Free shipping coupon', woocommerce ); 
  11.  
  12. $discount_amount_html = apply_filters( 'woocommerce_coupon_discount_amount_html', $discount_amount_html, $coupon ); 
  13. $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>'; 
  14.  
  15. echo wp_kses( apply_filters( 'woocommerce_cart_totals_coupon_html', $coupon_html, $coupon, $discount_amount_html ), array_replace_recursive( wp_kses_allowed_html( 'post' ), array( 'a' => array( 'data-coupon' => true ) ) ) );