Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tjanson

    (@tjanson)

    Thread Starter tjanson

    (@tjanson)

    Hola Oscar!

    Thank you very much for your reply.

    You guessed 4x right regarding my settings.

    But by now I found a very good solution thanks to combination of your great plug-in and some custom code.

    You plug-in does a great job, allowing me to:

    – Advertise one price incl. shipping all around the EU, while
    – offering non-EU customers a reduced price

    I only had to adjusted it so I don’t screw your compatriots from the Canary Islands 🙂

    I was actually close to making them their own country, but ChatGPT finally pulled it off right before I lost my belief in it.

    I looked a bit into your solution and wander: once you make the Canary Islands, a country property, do you really still need all this calculating? I would simply give the product the same absolute prize I charge e.g. Andorra. I only have one product for now with not too many following, so maybe that’s simply easier in my case.

    Wishing you all the best and thank you again for your help!

    Thread Starter tjanson

    (@tjanson)

    I asked ChatGPT:

    With a little back-and-forth, it was able to give me the following code that is placed at the bottom of the child theme’s functions.php:

    – – – snip – – –

    /**

    • Apply non-VAT price for special VAT-exempt regions everywhere
      */
      function apply_vat_exempt_price($price, $product) { if (!WC()->customer) return $price; $postcode = WC()->customer->get_shipping_postcode();
      $country = WC()->customer->get_shipping_country(); // VAT-exempt regions
      $vat_exempt_regions = [
      ‘ES’ => [’35’,’38’], // Canary Islands
      ‘IT’ => [‘23030′,’23041′,’22061’], // Livigno + Campione d’Italia
      ‘DE’ => [‘27498’], // Helgoland
      ]; foreach ($vat_exempt_regions as $c => $codes) {
      if ($country === $c) {
      foreach ($codes as $code) {
      if (strpos($postcode, $code) === 0) {
      return 72; // <– your non-VAT price
      }
      }
      }
      } return $price;
      }

    // Apply everywhere a product price is fetched
    add_filter(‘woocommerce_product_get_price’, ‘apply_vat_exempt_price’, 20, 2);
    add_filter(‘woocommerce_product_get_regular_price’, ‘apply_vat_exempt_price’, 20, 2);
    add_filter(‘woocommerce_product_get_sale_price’, ‘apply_vat_exempt_price’, 20, 2);
    – – – snap – – –

    On page results:
    1. Switzerland / postal code 12345: Must display 72€ / no VAT: OK
    2. Spain / postal code 12345: Must display 98€ / 21% Spanish VAT: OK
    3. Spain / postal code 38912: Must display 72€ / no VAT: OK

    Furthermore, I completed an order for scenario 3 and it makes it correctly to the WooCommerce > Orders backend. So this is not only browser-side cosmetics.

    I have no clue of coding PHP, I don’t even really understand HTML, CSS, but I think this took about an hour. Maybe there’s still a back hidden somewhere, but I thought I post this before I forget about it. Maybe somebody can make good use of it as well.

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