Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement