Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php // Don't copy me unless you need to!
/**
* Changes the coupon label output from Coupon: {code} to Coupon: {description}
*
* @param string $label the cart / checkout label
* @param \WC_Coupon $coupon coupon object
* @return string updated label
*/
function swwp_change_coupon_preview( $label, $coupon ) {
// WC 3.0+ compatibility
if ( is_callable( array( $coupon, 'get_description' ) ) ) {
$description = $coupon->get_description();
} else {
$coupon_post = get_post( $coupon->id );
$description = ! empty( $coupon_post->post_excerpt ) ? $coupon_post->post_excerpt : null;
}
return $description ? sprintf( esc_html__( 'Coupon: %s', 'woocommerce' ), $description ) : esc_html__( 'Coupon', 'woocommerce' );
}
add_filter( 'woocommerce_cart_totals_coupon_label', 'swwp_change_coupon_preview', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment