Advertisement
5ally

Untitled

Dec 12th, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  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 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement