Advertisement
imnguyen

discounts

Feb 22nd, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. add_filter( 'woocommerce_cart_subtotal', 'bbloomer_slash_cart_subtotal_if_discount', 99, 3 );
  2.  
  3. function bbloomer_slash_cart_subtotal_if_discount( $cart_subtotal, $compound, $obj ){
  4. global $woocommerce;
  5. if ( WC()->cart->total > 0 ) {
  6. $new_cart_subtotal = wc_price( WC()->cart->subtotal - $woocommerce->cart->get_cart_discount_tax_total() - $woocommerce->cart->get_cart_discount_total() );
  7. $cart_subtotal = sprintf( '<del>%s</del> <b>%s</b>', $cart_subtotal , $new_cart_subtotal );
  8. }
  9. return $cart_subtotal;
  10.  
  11. }
  12.  
  13.  
  14.  
  15.  
  16. //add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
  17. function woocommerce_custom_surcharge() {
  18. global $woocommerce;
  19.  
  20. if ( is_admin() && ! defined( 'DOING_AJAX' ) )
  21. return;
  22.  
  23. $percentage = 0.01;
  24. $surcharge = $woocommerce->cart->cart_contents_total-$woocommerce->cart->get_cart_discount_tax_total();
  25. $woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );
  26.  
  27. }
  28.  
  29.  
  30.  
  31. function prefix_add_discount_line( $cart ) {
  32.  
  33. $discount = $cart->subtotal - $cart_discount_tax_total - $cart_discount_total;
  34.  
  35. $cart->add_fee( __( 'Down Payment', 'yourtext-domain' ) , -$discount );
  36.  
  37. }
  38. add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement