Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jameskanestl

    (@jameskanestl)

    Okay, figured it out. In my custom shipping costs plugin, I simply insert the following lines:

    [shipping calculations based on cart are made and loaded into $cost]
    
    if (get_user_meta(get_current_user_id(), "freight_inclusive")) {
    			$cost = "0.0";
    		}

    Then inject the cost as per usual

    $this->add_rate( array(
    	      'id' 	=> $this->id,
    	      'label' => $this->title,
    	      'cost' 	=> $cost
    	    ));
    Thread Starter jameskanestl

    (@jameskanestl)

    Took a look at Taxamo. Could be wrong, but it seemed to me like they are still relying on rates, even if they are getting those rates via an API call. Thanks for the tip, nevertheless.

    Just to test the idea, I disabled all taxes and tax calculations from the Admin panel. I then plugged my API query logic into a new function in functions.php:

    add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_taxes_as_fee' );
    function woocommerce_custom_taxes_as_fee() {
    
    		// JSON for API call formulated and sent
    		// API response JSON received and tabulated as $total_tax
    
    		$woocommerce->cart->add_fee( 'Tax', $total_tax, true, '' );
    
    		// Error checking code, too, of course
    	}
    }

    Basically, because I named the fee “Tax” when I call add_fee(), it displays in the cart just below the subtotal exactly as if it were the standard tax calculation. The values I want get plugged in, the customer is charged the correct amount, and the amounts are tracked as necessary…

    Not exactly semantically on point but it seems like a good solution. Can you think of any potential downsides? As long as it’s well-documented and maintained, I hope this is a decent solution for this use case.

    Thread Starter jameskanestl

    (@jameskanestl)

    Hey, Mike. Thanks for taking an interest. It’s actually just a custom-baked REST API created by the client that integrates with their CRM and local databases. I send a query that looks like this:

    {
        "customerno":"ABC0001001",
        "state":"Georgia",
        "zip":"56544",
        "zipplus":"0000",
        "volume":"1,100.0",  // cart subtotal
        "freight":"10.5"  // shipping costs, also calculated via API
    }

    And it returns JSON like this:

    {
        "state": 76.346875000000011,
        "county": 5.5525,
        "city": 0,
        "district": 0
    }

    Those tax values are based on the client’s internal tax tables, customer non-profit status and some discount programs.

    Again, I’ve considered just disabling WooComm tax entirely, and tacking these values on to the cart as “Fees.” But if there is a good tax action hook or programatic way to directly inject tax values, that would be preferable, I suppose. As a last ditch, I think I could get them to edit the API to return the rates rather than the values, but even then I’m not 100% sure what the ideal approach would be… Any thoughts? Resources to help me look into the issue of tax calculation further? I know there’s a way to make this work.

    jameskanestl

    (@jameskanestl)

    File permissions have to do with your web server, and not the plugin code itself. It sounds like your plugin files were created/copied without sufficient access permissions, but no one on here can help you with that without access to your server. That is probably why you were met with silence.

    There’s two possibilities: If you manage your server yourself, you can SSH into your host server and change the permissions of the relevant files using the command-line interface. Once you have SSH access, “chmod” is the command you’ll want to use on plugin files – you can Google around and figure it out.

    Alternatively, maybe someone else manages your server. You can often open a ticket with your hosting company, explain the issue to them, and many will fix the issue themselves and alert you when they’re done. Guessing this is the route you’ll want to take.

Viewing 4 replies - 1 through 4 (of 4 total)