Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'woocommerce_cart_totals_get_item_tax_rates', function( $item_tax_rates, $item, $cart ) {
- if ( ! $cart->needs_shipping() ) return $item_tax_rates;
- $packages = $cart->get_shipping_packages();
- if ( empty( $packages ) ) return $item_tax_rates;
- $product_id = $item->product->get_id();
- if ( ! $product_id ) return $item_tax_rates;
- $pvendor_id = wcfm_get_vendor_id_by_post( $product_id );
- if ( ! $pvendor_id ) return $item_tax_rates;
- foreach ( $packages as $svendor_id => $package ) {
- if( function_exists( 'wcfm_is_vendor' ) && wcfm_is_vendor( $svendor_id ) && ( $pvendor_id == $svendor_id ) ) {
- $chosen_method = isset( WC()->session->chosen_shipping_methods[ $svendor_id ] ) ? WC()->session->chosen_shipping_methods[ $svendor_id ] : '';
- $id = explode(":", $chosen_method, 2);
- $id = $id[0];
- $vendor_data = get_user_meta( $pvendor_id, 'wcfmmp_profile_settings', true );
- $calculate_tax_for = array();
- $calculate_tax_for['city'] = isset( $vendor_data['address']['city'] ) ? $vendor_data['address']['city'] : '';
- $calculate_tax_for['postcode'] = isset( $vendor_data['address']['zip'] ) ? $vendor_data['address']['zip'] : '';
- $calculate_tax_for['country'] = isset( $vendor_data['address']['country'] ) ? $vendor_data['address']['country'] : '';
- $calculate_tax_for['state'] = isset( $vendor_data['address']['state'] ) ? $vendor_data['address']['state'] : '';
- $location = array(
- $calculate_tax_for['country'],
- $calculate_tax_for['state'],
- $calculate_tax_for['postcode'],
- $calculate_tax_for['city'],
- );
- $tax_class = $item->product->get_tax_class();
- if ( count( $location ) === 4 ) {
- list( $country, $state, $postcode, $city ) = $location;
- $item_tax_rates = WC_Tax::find_rates(
- array(
- 'country' => $country,
- 'state' => $state,
- 'postcode' => $postcode,
- 'city' => $city,
- 'tax_class' => $tax_class,
- )
- );
- }
- break;
- }
- }
- return $item_tax_rates;
- }, 500, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement