I'd been using the following to decide if a checkout field needed to be complete or not...
if ($posted['shipping_method'] == "local_pickup_plus") {
}
Since updating to WooCommerce 2.1, my code no longer works.
I've tried to echo the value stored in $posted['shipping_method'] to see if I'm checking it against the correct value, but it appears nothing is stored in this variable anymore.
I've been looking for other methods of checking the chosen shipping method, but I'm not getting very far.
Any assistance would be greatly appreciated.
Been looking for this for a couple of hours, then decided to delve into the WooCommerce files...
This seems to be working for me:
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
I'm using this to set a min total for local delivery by using it like this in my functions.php
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
$min_spend = 25;
$cart_total = $woocommerce->cart->cart_contents_total;
if (($cart_total < 25) AND ($chosen_shipping == 'local_delivery')) {
$surcharge = $min_spend-$cart_total;
$woocommerce->cart->add_fee( 'Delivery Surchage', $surcharge, true, 'standard' );
}
}
Hope this helps someone out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With