Forked from bekarice/update-woocommerce-coupon-label.php
Created
September 5, 2019 08:45
-
-
Save shamimsdp/debe3a8981e36d453a5d9f81a068f3e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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