forked from qreuz/woocommerce-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce-conditional-suffix-for-vat-and-free-shipping.php
70 lines (58 loc) · 3.05 KB
/
woocommerce-conditional-suffix-for-vat-and-free-shipping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
*
* ██████╗ ██████╗ ███████╗██╗ ██╗███████╗
*██╔═══██╗██╔══██╗██╔════╝██║ ██║╚══███╔╝
*██║ ██║██████╔╝█████╗ ██║ ██║ ███╔╝
*██║▄▄ ██║██╔══██╗██╔══╝ ██║ ██║ ███╔╝
*╚██████╔╝██║ ██║███████╗╚██████╔╝███████╗
* ╚══▀▀═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚══════╝
*
* QREUZ SNIPPET FOR WOOCOMMERCE
* This file is part of a collection of snippets to be used on your WooCommerce store.
* !! Do not put this file in your Wordpress installation !!
*
* Copy/paste the code below and add it to the functions.php of your child theme.
* Don't know what a child theme is? Read this post: https://qreuz.com/how-to-use-a-child-theme-on-wordpress-and-woocommerce/
*
* COPY AND PASTE EVERYTHING BELOW THIS LINE TO YOUR FUNCTIONS.PHP **/
/**
* QREUZ SNIPPET FOR WOOCOMMERCE
* @TITLE: WooCommerce Conditional Suffix for VAT and Free Shipping Scenarios
* @DESCRIPTION: shows a price suffix if VAT is applied and if free shipping is available
* @DOCUMENTATION AND DISCUSSION: https://qreuz.com/snippets/woocommerce-conditional-suffix-for-vat-and-free-shipping-scenarios/
* @AUTHOR: Qreuz GmbH
* @VERSION: 1.0
*/
add_filter( 'woocommerce_get_price_suffix', 'qreuz_price_suffix', 10, 4 );
function qreuz_price_suffix( $price_display_suffix, $product ) {
if (isset( WC()->customer )) {
$shipping_country = WC()->customer->get_shipping_country();
// define list of countries in the European Union to apply VAT, replace them with your countries to apply VAT for (if applicable)
$eu_countries = array('BE','BG','CZ','DK','DE','EE','IE','EL','ES','FR','HR','IT','CY','LV','LT','LU','HU','MT','NL','AT','PL','PT','RO','SI','SK','FI','SE','UK');
if (in_array($shipping_country,$eu_countries) && $product->is_taxable()){
$vat = 'inc. 19% VAT. '; // the suffix to show if VAT is applied, replace with your VAT rate
$price = wc_get_price_including_tax($product);
}
else {
$vat = '';
$price = wc_get_price_excluding_tax($product);
}
$free_shipping_treshold = 25; // enter the amount an order needs to be eligible for free shipping
if ($price < $free_shipping_treshold && $product->needs_shipping()){
$shipping = 'plus shipping'; // suffix for 'excl. shipping' scenario
}
elseif ($price >= $free_shipping_treshold && $product->needs_shipping()){
$shipping = 'free shipping'; // suffix for 'free shipping' scenario
}
else {
$shipping = '';
}
$suffix = $vat.$shipping;
$suffix_output = '<small class=\'woocommerce-price-suffix\'>'. $suffix .'</small>';
return $suffix_output;
}
else {
return $price_display_suffix;
}
}