Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php // Don't copy me unless you need to!
  2.  
  3. /**
  4. * Changes the coupon label output from Coupon: {code} to Coupon: {description}
  5. *
  6. * @param string $label the cart / checkout label
  7. * @param \WC_Coupon $coupon coupon object
  8. * @return string updated label
  9. */
  10. function swwp_change_coupon_preview( $label, $coupon ) {
  11.  
  12. // WC 3.0+ compatibility
  13. if ( is_callable( array( $coupon, 'get_description' ) ) ) {
  14. $description = $coupon->get_description();
  15. } else {
  16. $coupon_post = get_post( $coupon->id );
  17. $description = ! empty( $coupon_post->post_excerpt ) ? $coupon_post->post_excerpt : null;
  18. }
  19.  
  20. return $description ? sprintf( esc_html__( 'Coupon: %s', 'woocommerce' ), $description ) : esc_html__( 'Coupon', 'woocommerce' );
  21. }
  22. add_filter( 'woocommerce_cart_totals_coupon_label', 'swwp_change_coupon_preview', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement