SHARE
TWEET

Untitled

5ally Dec 12th, 2018 (edited) 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Details: https://wordpress.stackexchange.com/questions/321284/override-woocommerce-wc-class-function
  3. // Start copy below, if you want to..
  4.  
  5. // $total is the cart's grand total, including total shipping cost.
  6. // $cart is the cart object - the same as you'd get with wc()->cart.
  7. function rename_me( $total, $cart ) {
  8.     $cat_ids = array();
  9.     foreach ( $cart->get_cart() as $cart_item ) {
  10.         $cat_ids = array_merge(
  11.             $cat_ids, $cart_item['data']->get_category_ids()
  12.         );
  13.     }
  14.  
  15.     $cat_id = 39;
  16.     $count = count( $cat_ids );
  17.  
  18.     // Subtracts the total shipping cost from $total.
  19.     if ( 1 === $count && in_array( $cat_id, $cat_ids ) ) {
  20.         return $total - $cart->get_shipping_total();
  21.     }
  22.     // Returns original $total.
  23.     return $total;
  24. }
  25. add_filter( 'woocommerce_calculated_total', 'rename_me', 10, 2 );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top