• Resolved reydempto

    (@reydempto)


    I have to display some specific disclaimers on my invoices depending on which country the customers are in.

    For example, our German-bound orders need to have this simple text in their invoice, by law as of 2017: Zwischensumme inkl. 19% MwSt. Versandkosten steuerfrei.

    After reading this thread I tried adding this to my custom template:

    <?php if( $this->order->_billing_country = 'DE' ) : ?>
    <?php echo "DE: Zwischensumme inkl. 19% MwSt. Versandkosten steuerfrei.
    <?php endif; ?>
    

    It does indeed display the info, however the “if” statement is ignored and it displays the text no matter what country is defined in _billing_country! What am I doing wrong?

    • This topic was modified 7 years, 10 months ago by reydempto.
    • This topic was modified 7 years, 10 months ago by reydempto.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! There are two errors in your if statement:

    • If you use the ‘magic getter’, you have to omit the underscore, as WooCommerce already adds this in the magic getter methods before trying to fetch the meta. i.e: $this->order->billing_country should work
    • = means ‘make equal to’. You want ‘==’ (‘compare to / is equal to’).

    Putting it together:

    
    <?php if( $this->order->billing_country == 'DE' ) : ?>
    <?php echo "DE: Zwischensumme inkl. 19% MwSt. Versandkosten steuerfrei.
    <?php endif; ?>
    

    should do the trick ??

    Hope that helps!
    Ewout

    • This reply was modified 7 years, 10 months ago by Ewout.
    Thread Starter reydempto

    (@reydempto)

    That helped immensely, thank you! I have to give one of three different messages depending on which region the billing address is in.

    I have continued the code like this:

    <?php if( $this->order->billing_country == 'DE' ) : ?>
    <?php echo "Zwischensumme inkl. 19% MwSt. Versandkosten steuerfrei." ?>
    <?php endif; ?>
    
    <?php if( $this->order->billing_country == 'AL,AD,AT,BY,BE,BA,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GI,GR,HU,IS,IE,IM,IT,RS,LV,LI,LT,LU,MK,MT,MD,MC,ME,NL,NO,PL,PT,RO,RU,SM,RS,SK,SI,ES,SE,CH,UA,GB,VA,RS' ) : ?>
    <?php echo "Tax free § 4 Nr. 1b UStG / Intra - Community Delivery." ?>
    <?php endif; ?>
    
    <?php if( $this->order->billing_country != 'DE,AL,AD,AT,BY,BE,BA,BG,HR,CY,CZ,DK,EE,FO,FI,FR,GI,GR,HU,IS,IE,IM,IT,RS,LV,LI,LT,LU,MK,MT,MD,MC,ME,NL,NO,PL,PT,RO,RU,SM,RS,SK,SI,ES,SE,CH,UA,GB,VA,RS' ) : ?>
    <?php echo "Tax free export!" ?>
    <?php endif; ?>

    The first part works fine. If the billing_country is DE, we get the German tax message.

    The second part is for within the EU, and the third part is for the rest of the world. However, if the billing_country is anything else besides DE, I get message three (rest of the world). My guess is that it’s not possible to use a comma’d list of country codes like this..it just made sense in my mind to use the same comma’d list of country codes and just say “if this DOES NOT equal, give x response”.

    EDIT: I have figured out how to do this bit! I created an array of the country codes necessary:

    <?php if( $this->order->billing_country == 'DE' ) : ?>
    <?php echo "Zwischensumme inkl. 19% MwSt. Versandkosten steuerfrei." ?>
    <?php endif; ?>
    
    <?php
    $country_codes = array("AL","AD","AT","BY","BE","BA","BG","HR","CY","CZ","DK","EE","FO","FI","FR","GI","GR","HU","IS","IE","IM","IT","RS","LV","LI","LT","LU","MK","MT","MD","MC","ME","NL","NO","PL","PT","RO","RU","SM","RS","SK","SI","ES","SE","CH","UA","GB","VA","RS");
         if (in_array($this->order->billing_country, $country_codes)) {
             echo "Tax free § 4 Nr. 1b UStG / Intra - Community Delivery.";
         }
         if (!in_array($this->order->billing_country, $country_codes)) {
             echo "Tax free export!";
         }
    ?>

    Now it works fine. Thank you so much for your help, you really put me on the right track. Great plugin!!

    • This reply was modified 7 years, 10 months ago by reydempto.
    • This reply was modified 7 years, 10 months ago by reydempto.
    • This reply was modified 7 years, 10 months ago by reydempto.
    • This reply was modified 7 years, 10 months ago by reydempto.
    • This reply was modified 7 years, 10 months ago by reydempto.
    • This reply was modified 7 years, 10 months ago by reydempto.
    • This reply was modified 7 years, 10 months ago by reydempto.
    • This reply was modified 7 years, 10 months ago by reydempto.
    Plugin Contributor Ewout

    (@pomegranate)

    Great, very glad to hear that’s resolved now. As a bonus you learned some PHP on the way ??

    If you can spare a minute, I would really appreciate a plugin review here: https://www.ads-software.com/support/plugin/woocommerce-pdf-invoices-packing-slips/reviews/#new-post

    Thanks in advance!
    Ewout

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display custom text based on _billing_country’ is closed to new replies.