• A couple of years ago you gave me a solution to deactivate invoices for purchases from a certain country, but recently it has stopped working.

    Have there been any changes due to any updates to both WordPress and WooCommerce?

    Your solution was the following, but now it doesn’t work.

    // exclude certain countries from automatic pdf creation
    add_filter( ‘wpo_wcpdf_custom_attachment_condition’, ‘wpo_wcpdf_exclude_country’, 100, 4 );
    function wpo_wcpdf_exclude_country( $condition, $order, $status, $document ) {
    $country = $order->get_billing_country();
    if ( $document == ‘invoice’ && $country == ‘NL’ ) {
    return false;
    } else {
    return $condition;
    }
    }

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor kluver

    (@kluver)

    Hi @groodo,

    That code snippet should still prevent the invoice from attaching to any email when the billing country is the Netherlands.

    Are you sure the code snippet is actively called?

    • This reply was modified 4 years, 1 month ago by kluver.
    Thread Starter groodo

    (@groodo)

    The code is in my functions.php file, but how can I check that it works?

    As I mentioned before, it seems to have stopped working after some update, but I don’t know if it’s from WooCommerce or WordPress. I only realized at the time that I had a purchase from a certain country for which the invoice did not have to be added.

    Thank you.

    Plugin Contributor kluver

    (@kluver)

    You could add a die() including a message to the top of the filter and send a test email. If the filter is called this would stop the entire process and will print the message. You should do this on a staging site though because a customer placing an order will also trigger the filter and break the site.

    Snippet including the die() at the top:

    add_filter( 'wpo_wcpdf_custom_attachment_condition', 'wpo_wcpdf_exclude_country', 100, 4 );
    function wpo_wcpdf_exclude_country( $condition, $order, $status, $document ) {
    	die('The filter was called.');
    	$country = $order->get_billing_country();
    	if ( $document == 'invoice' && $country == 'NL' ) {
    		return false;
    	} else {
    		return $condition;
    	}
    }
    • This reply was modified 4 years, 1 month ago by kluver.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Deactivate invoices for purchases in a given country’ is closed to new replies.