shipping

WooCommerce - Hide other shipping methods when FREE SHIPPING is available

半城伤御伤魂 提交于 2019-11-27 05:38:42
I would like to hide other shipping options when free shipping is available on Woocommerce. Because latest version of woocommerce now is still showing other shipping options even if there's FREE shipping option. Please help There is this recent code snippet for WooCommerce 2.6+. that you can try: add_filter( 'woocommerce_package_rates', 'hide_other_shipping_when_free_is_available', 100, 2 ); function hide_other_shipping_when_free_is_available( $rates, $package ) { $free = array(); foreach ( $rates as $rate_id => $rate ) { if ( 'free_shipping' === $rate->method_id ) { $free[ $rate_id ] = $rate;

Hide shipping methods for specific shipping class in WooCommerce

时间秒杀一切 提交于 2019-11-27 05:29:54
Essentially I'm trying to make the flat rate method Id flat_rate:7 disabled when there is cart items that have the shipping class "Roller" (ID 92 ). This is the code I tried: add_filter('woocommerce_package_rates', 'wf_hide_shipping_method_based_on_shipping_class', 10, 2); function wf_hide_shipping_method_based_on_shipping_class($available_shipping_methods, $package) { $hide_when_shipping_class_exist = array( 92 => array( 'flat_rate:7' ) ); $shipping_class_in_cart = array(); foreach(WC()->cart->cart_contents as $key => $values) { $shipping_class_in_cart[] = $values['data']->get_shipping_class

Get orders shipping method details in WooCommerce 3

旧巷老猫 提交于 2019-11-27 01:46:36
问题 How can I get the order shipping method id .... For example 'flate_rate'. Since WooCommerce 3.x.x it's not so easy as everything has changed. I have try it with $order->get_data() in a foreach loop but the data is protected. 回答1: If you want to get the Order Items Shipping data, you need first to get them in a foreach loop (for 'shipping' item type) and to use WC_Order_Item_Shipping methods to access data $order_id = 528; // For example // An instance of $order = wc_get_order($order_id); //

Hide shipping methods for specific shipping class in WooCommerce

这一生的挚爱 提交于 2019-11-26 11:32:30
问题 Essentially I\'m trying to make the flat rate method Id flat_rate:7 disabled when there is cart items that have the shipping class \"Roller\" (ID 92 ). This is the code I tried: add_filter(\'woocommerce_package_rates\', \'wf_hide_shipping_method_based_on_shipping_class\', 10, 2); function wf_hide_shipping_method_based_on_shipping_class($available_shipping_methods, $package) { $hide_when_shipping_class_exist = array( 92 => array( \'flat_rate:7\' ) ); $shipping_class_in_cart = array(); foreach