Banner Logo

Be a part of the family: Connect, Receive Support,
Contribute, and Reap Abundant Rewards!

bill.antoniadis

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • in reply to: Calculate Tax Based on Vendor’s Address #136288
    bill.antoniadis
    Participant

    We’d like to come back to this issue. I’ve summed our progress up in the below question fully with some code examples. I’ve worded this in a way that we can post on other support forums but it’s WCMp-related in nature:

    Question:

    How to change Woocommerce vendor address during Cart/Checkout for use in Woocommerce Tax calculations?

    Description:

    TL;DR – Is there a way to alter the address WooCommerce Tax uses for the tax nexus using a filter/hook upon loading the cart and checkout pages? We tried (see below) and it didn’t work.

    We are using a WordPress plugin for WooCommerce called WC-Marketplace (WCMp) to create a multi-vendor platform that allows vendors in our market to sell goods. Everything works as expected except for taxes. We only want to charge sales tax if the vendor and the customer reside in the same state. I understand this sounds like a product specific question but we have reason to believe it needs to be handled with code that’s specific to WooCommerce.

    https://multivendorx.com/

    Example of what we want:

    Vendor is in Ohio, Customer is in Ohio = Sales tax applied
    Vendor is in California, Customer is in Ohio = No tax applied
    We’re using WC Tax to automatically calculate sales tax within the USA. However, it seems to be using the address found in WooCommerce > Settings > General on the admin dashboard instead of the actual vendor’s address configured in their WCMp dashboard which is stored as an entry in the wp_usermeta table.

    https://woocommerce.com/products/tax/

    Example:

    Vendor is in California, Customer is in Ohio = Behaves as if Vendor is in Ohio as our general settings are configured to Ohio in this scenario.
    We reached out to WCMp support and the way we they put it to us, we’ll need to write code to intercept the tax calculation ourselves. We believe it’s possible to do this using an filter/hook and override it with the correct address before taxes are calculated.

    After reading through WooCommerce documentation and code itself, here’s code I wrote to accomplish this:

    
    //
    // Change tax location to use vendor location
    function custom_woocommerce_order_get_tax_location( $args, $instance ) {
        global $woocommerce;
    
        // Get vendor based on product ID
        $vendor_id = '';
        foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ){
            $post_obj    = get_post( $cart_item['product_id'] );
            $post_author = $post_obj->post_author;
            $vendor_id = $post_author;
            break;
        }
    
        if ($vendor_id) {
        // Set tax location based on vendor
            $args = [];
            $args['country']    = metadata_exists( 'user', $vendor_id, '_vendor_country' )  ? get_user_meta($vendor_id, '_vendor_country', true):'';
            $args['state']      = metadata_exists( 'user', $vendor_id, '_vendor_state' )    ? get_user_meta($vendor_id, '_vendor_state', true):'';
            $args['postcode']   = metadata_exists( 'user', $vendor_id, '_vendor_postcode' ) ? get_user_meta($vendor_id, '_vendor_postcode', true):'';
            $args['city']       = metadata_exists( 'user', $vendor_id, '_vendor_city' )     ? get_user_meta($vendor_id, '_vendor_city', true):'';
        }
    
        return $args;
    }
    add_filter('woocommerce_order_get_tax_location', 'custom_woocommerce_order_get_tax_location', 10, 2);
    
    Copy

    In short, the above recurses through items in the cart and gets the WCMp vendor’s ID based on which WP user created it (always the vendor). It then uses the vendor_id to get the address metadata from the wp_usermeta table and override the woocommerce_order_get_tax_location filter’s $args.

    This is the code for that filter, get_tax_location()

    https://woocommerce.github.io/code-reference/files/woocommerce-includes-abstracts-abstract-wc-order.html#source-view.1524

    I believe this is working to some extent as when I print out the WC Object, we see in the WC_Customer Object that the correct vendor’s State and Zip Code are listed as so:

    
    [changes:protected] => Array
    (
        [shipping] => Array
            (
                [postcode] => 90003
                [city] => Los Angeles
                [address_1] => 
                [address_2] => 
                [state] => CA
            )
    )
    
    Copy

    Unfortunately, the tax is still being calculated as if our business is the tax nexus and not the vendor.

    What is the correct way to intercept and change the vendor address WC Tax uses before the cart and Checkout pages load the taxes?

    Thanks a million!

    in reply to: Bugs / Oddities with the Refund feature #135652
    bill.antoniadis
    Participant

    Thank you for the reply! Regarding issue #1 we see you’re not refunding the full amount of 121 euros. We are attempting to refund the full amount which is where we see this error. Can you show us a video of you refunding the full amount?

    Thanks!

    in reply to: Bugs / Oddities with the Refund feature #135580
    bill.antoniadis
    Participant

    A follow up question on refunds. When the vendor approves the customer refund request and enters the amount to refund, does that refund then get sent to Stripe? We tested this and we don’t see anything in Stripe that indicates a refund was initiated.

    in reply to: Bugs / Oddities with the Refund feature #135549
    bill.antoniadis
    Participant

    Sounds good. We’re meeting to review this today and tomorrow.

    bill.antoniadis
    Participant

    Here is the information we want to display on the Order page from the /dashboard/transaction-details/{ID} page

    We want Total Earned on the Order page to reflect the subtracted Gateway Fee and display the Gateway Fee as a line item.

    bill.antoniadis
    Participant

    Please find this is where we want to make the addition/change.

    in reply to: Calculate Tax Based on Vendor’s Address #134896
    bill.antoniadis
    Participant

    Also, I’m attempting to use the above link to test per product tax and it’s not saving when I update the product.

    in reply to: Calculate Tax Based on Vendor’s Address #134895
    bill.antoniadis
    Participant

    Hi, developer here.

    Currently I’m attempting to modify your example for per-product tax rates to do this:

    https://multivendorx.com/tech-blog/vendor-per-product-tax/

    Particularly by using the

    woocommerce_cart_totals_get_item_tax_rates
    Copy

    filter. My thought process is to use the product id to get the vendor id associated with the product, compare the vendor and customer locations, and set the tax rate based on that. The WCMp REST API does not seem to provide any feature to get the vendor id by product id so I’m looking both into doing this manually through SQL or using one of WCMp’s vendor functions but am still working through this.

    I’m also noticing that the tax rates still seem to need to be manually set per state/etc so am currently investigating the connection between woocommerce tax and jetpack.

    Does one of your developers know of a way to get the vendor’s address based on the products in the cart and then set the address being used by woocommerce tax plugin to that address when this filter runs?

    in reply to: Calculate Tax Based on Vendor’s Address #134834
    bill.antoniadis
    Participant

    Thank you for your reply. Assuming this question has come up before, do your developers have any sample code or suggestions of where to make the change?

    bill.antoniadis
    Participant

    We were able to resolve this issue by deactivating the WooCommerce Stripe plugin.

    bill.antoniadis
    Participant

    Please find that I’ve attached a video of me attempting to save shipping data from my account both with and without the stripe marketplace plugin enabled.

    I had to use Google Drive as the filesize is too large to upload here

    https://drive.google.com/file/d/1_0ltSmkVdzgWFa4St0jtI3UcjYmwmQ4y/view?usp=sharing

    bill.antoniadis
    Participant

    Please find that I’ve attached a video of me attempting to save shipping data from my account both with and without the stripe marketplace plugin enabled.

    bill.antoniadis
    Participant

    See attached

    in reply to: Trouble with both Dashboard and Store when using WCMp AFM #132848
    bill.antoniadis
    Participant
    This reply has been marked as private.
    in reply to: Trouble with both Dashboard and Store when using WCMp AFM #132845
    bill.antoniadis
    Participant
    This reply has been marked as private.
Viewing 15 posts - 1 through 15 (of 21 total)