• Hi there,
    We sell mostly to private customers and that is why we don’t mention the taxes on the invoices. In WooCommerce the tax option is off.But occasionally a company orders and wants to have an invoice with taxes. Now we make those invoices by hand. The trigger is pretty simple… if the company field is filled, it should be an invoice with taxes. If that field isn’t filled, without taxes.
    Can that be done with your excellent plugin?
    Thanks,
    Jan

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @janvanarkel,

    From what I understand about WooCommerce, I don’t think this will be possible. If you disable the taxes, then there will be no taxes in the order back-end, meaning no tax information available for our plugin to grab.

    I think the more likely solution would be to enable taxes for everyone, then use some snippet to hide them for everyone, except if the company field is present.
    The snippet would then look something like this:

    add_filter( 'wpo_wcpdf_woocommerce_totals', 'wpo_wcpdf_custom_totals', 10, 3 );
    function wpo_wcpdf_custom_totals ($totals, $order, $document_type) {
    
    	// grab the company field
    	$billing_company = $order->get_billing_company();
    	
    	// if there is no company, hide various taxes
    	if ( $billing_company == '' || ctype_space($billing_company) == true ) { 
    		// hide the tax label AND value to make it disappear
    		$totals['us-us-1']['label'] = null;
    		$totals['us-us-1']['value'] = null;
    	}
    	
    	// return totals, so they are visible on invoice
    	return $totals;
    }

    The only catch is that you have to know the names of all the taxes you don’t want to show. In the example above, I’m hiding the “us-us-1” tax. My recommended way of finding the name: when looking at an invoice, enter “&output=html” at the end of the URL & your invoice will switch to an HTML view. Afterwards, inspect the tax by right-clicking & you’ll see something like this:

    Screenshot-2021-02-26-18-16-12

    If you haven’t worked with action hooks before, check this guide out: https://docs.wpovernight.com/general/how-to-use-filters/

    I really hope this helps somewhat!

    Hey,
    Is there no possible way to do it like @janvanarkel mentioned because this would be ideal for many shops I have !

    Plugin Contributor Darren Peyou

    (@dpeyou)

    Hi @nesoor,

    Sadly no, because then the taxes wouldn’t be available in the order information if disabled, meaning the PDF Invoices will have no tax information that it would be able to reach at all. ??
    That was why I proposed the solution above. I understand it isn’t ideal, since you have to know the name of all the taxes you’d want to hide by default.

    Short reference: https://docs.wpovernight.com/woocommerce-pdf-invoices-packing-slips/displaying-taxes/#taxes-missing

    Thread Starter janvanarkel

    (@janvanarkel)

    Thank you for your suggestion, dpeyou. I’m going to give it a try. But if I understand you correctly, that will avoid seeing tax info on screen. And then on paper? That means a layout with tax info and a layout without tax info? Or does everybody get an invoice with tax info? And then the user does need to select the right invoice? Or what?

    • This reply was modified 3 years, 8 months ago by janvanarkel.
    Plugin Contributor Darren Peyou

    (@dpeyou)

    @janvanarkel,

    So from the code above, let’s say my shop ONLY has the “US tax” (us-us-1), this tax is hidden by default for everyone, EXCEPT if the company field is non-empty (or non-whitespace). ??

    So if you have a lot of taxes that need to be hidden by default, you need to add these to lines (from the code above), making both the ‘label’ & the ‘value’ null:

    Excerpt from code above:

    
    // hide us-us-1 tax
    $totals['us-us-1']['label'] = null;
    $totals['us-us-1']['value'] = null;
    

    The downside to this is that the list could get very long if you had many taxes in your shop, so 5 different taxes = at least 10 additional lines of code.
    I hope that makes sense & helps!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Invoices with taxes’ is closed to new replies.