I want the coupon to appear on my cart total and on my coupon section. Right now coupon code appear on my cart total and on my cart coupon section. But I want to change it a little bit.
For default, it shows like "coupon: couponcode and then $10 with the remove link."
I want it to print the cart % discount "15% off " for cart total and my coupon section. For my cart total I don't want the "remove link" to appear. I attach an image, I want to look something like that.
For example, I want it look like this.
Cart total - 15% off and then $10.00. Cart coupon - couponcode 15% off and then "remove" link, the remove link is you can remove the couponcode.
Wc-cart-functions.php.
I know this make the coupon work. How do I print the discount type. If I remove the "remove" link, it will remove for carts total and my coupon section. But I just want it to remove in my cart total and I want the "Remove" link appear on my coupon section. How do that?
/**
* Get a coupon label
*
* @access public
* @param string $coupon
*/
function wc_cart_totals_coupon_label( $coupon ) {
if ( is_string( $coupon ) )
$coupon = new WC_Coupon( $coupon );
echo apply_filters( 'woocommerce_cart_totals_coupon_label', esc_html( __( 'Coupon:', 'woocommerce' ) . ' ' . $coupon->code ), $coupon );
}
/**
* Get a coupon value
*
* @access public
* @param string $coupon
*/
function wc_cart_totals_coupon_html( $coupon ) {
if ( is_string( $coupon ) ) {
$coupon = new WC_Coupon( $coupon );
}
$value = array();
if ( $amount = WC()->cart->get_coupon_discount_amount( $coupon->code, WC()->cart->display_cart_ex_tax ) ) {
$discount_html = wc_price( $amount );
} else {
$discount_html = '';
}
$value[] = apply_filters( 'woocommerce_coupon_discount_amount_html', $discount_html, $coupon );
if ( $coupon->enable_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->code ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? WC()->cart->get_checkout_url() : WC()->cart->get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->code ) . '">' . __( '[Remove]', 'woocommerce' ) . '</a>';
echo apply_filters( 'woocommerce_cart_totals_coupon_html', $value, $coupon );
}
Cart Coupon (cart-totals.php)
<ul class="cart_totals <?php if ( WC()->customer->has_calculated_shipping() ) echo 'calculated_shipping'; ?>">
<?php do_action( 'woocommerce_before_cart_totals' ); ?>
<li>
<span class="label"><?php _e( 'Subtotal', 'woocommerce' ); ?></span>
<span class="value"><?php wc_cart_totals_subtotal_html(); ?></span>
</li>
<?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
<li class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
<span class="label"><?php wc_cart_totals_coupon_label( $coupon ); ?></span>
<span class="value"><?php wc_cart_totals_coupon_html( $coupon ); ?></span>
</li>
<?php endforeach; ?>
<?php do_action( 'woocommerce_after_cart_totals' ); ?>
</ul>
Coupon section (cart.php)
<section class="row-wrap prod-wrap">
<div class="row-inner">
<form action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" method="post">
<?php do_action( 'woocommerce_before_cart_table' ); ?>
<div id="coupon">
<?php foreach ( WC()->cart->get_coupons() as $code => $coupon ) : ?>
<li class="cart-discount coupon-<?php echo esc_attr( sanitize_title( $code ) ); ?>">
<span class="label"><?php wc_cart_totals_coupon_label( $coupon ); ?></span>
<span class="value"><?php wc_cart_totals_coupon_html( $coupon ); ?></span>
</li>
<?php endforeach; ?>
</div>
<?php do_action( 'woocommerce_after_cart_table' ); ?>
</form>
</div>
</section>
</div>