Created
January 14, 2021 06:10
-
-
Save daveloodts/a36a27a8efdc08871eeebb5ea461c16a to your computer and use it in GitHub Desktop.
Tekst in WooCommerce checkout afhankelijk verzendzone en bedrag in winkelmand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'woocommerce_review_order_after_shipping' , 'shipping_zone_targeted_postcodes_afhaal2030' ); | |
function shipping_zone_targeted_postcodes_afhaal2030() { | |
// HERE DEFINE YOUR SHIPPING ZONE NAME(S) | |
$targeted_zones_names = array('Verzendzones 20 euro', 'Verzendzone 30 euro'); // <====== <====== <====== <====== <====== | |
// Get the customer shipping zone name | |
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); // The chosen shipping mehod | |
$chosen_method = explode(':', reset($chosen_methods) ); | |
$shipping_zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $chosen_method[1] ); | |
$current_zone_name = $shipping_zone->get_zone_name(); | |
if ($current_zone_name == 'Verzendzone 30 euro') { $min_amount = 30; } | |
elseif ($current_zone_name == 'Verzendzones 20 euro') { $min_amount = 20; } | |
$current = WC()->cart->subtotal; | |
$difprice = wc_price( $min_amount - $current ); | |
if ( $current < $min_amount ) { | |
if( in_array( $current_zone_name, $targeted_zones_names ) ){ | |
echo '<tr class="shipping woofership"> | |
<td colspan="2" style="text-align:center">' . sprintf( | |
__( "<strong>Enkel afhaal mogelijk</strong>. Voor gratis verzending,<br/> bestel nog <u>minstens voor $difprice</u>", "woocommerce"), | |
) . '</td> | |
</tr>'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment