Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Details: https://wordpress.stackexchange.com/questions/321284/override-woocommerce-wc-class-function
- // Start copy below, if you want to..
- // $total is the cart's grand total, including total shipping cost.
- // $cart is the cart object - the same as you'd get with wc()->cart.
- function rename_me( $total, $cart ) {
- $cat_ids = array();
- foreach ( $cart->get_cart() as $cart_item ) {
- $cat_ids = array_merge(
- $cat_ids, $cart_item['data']->get_category_ids()
- );
- }
- $cat_id = 39;
- $count = count( $cat_ids );
- // Subtracts the total shipping cost from $total.
- if ( 1 === $count && in_array( $cat_id, $cat_ids ) ) {
- return $total - $cart->get_shipping_total();
- }
- // Returns original $total.
- return $total;
- }
- add_filter( 'woocommerce_calculated_total', 'rename_me', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement