Skip to content

Instantly share code, notes, and snippets.

@bekarice
Created March 24, 2017 21:23
Show Gist options
  • Select an option

  • Save bekarice/0a61a4130b0edba033fa737676f4c71a to your computer and use it in GitHub Desktop.

Select an option

Save bekarice/0a61a4130b0edba033fa737676f4c71a to your computer and use it in GitHub Desktop.
<?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 );
@fabwintle

Copy link
Copy Markdown

This does not work anymore on my install on version 6.9.4. @bekarice is this still working for you?

@sdowney2002

Copy link
Copy Markdown

Seems to be working just fine on 7.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment