shipping

Woocommerce, hide shipping method based on shipping class

本小妞迷上赌 提交于 2019-11-29 21:36:07
问题 I'm trying to hide all but one shipping method based on the shipping class, essentially forcing the FedEx overnight method when a product belonging to a specific class is selected. I'm starting with this code, and modifying it as indicated below: add_filter( 'woocommerce_available_shipping_methods', 'hide_shipping_based_on_class' , 10, 1 ); function check_cart_for_share() { // load the contents of the cart into an array. global $woocommerce; $cart = $woocommerce->cart->cart_contents; $found =

Remove shipping cost if custom checkbox is checked in WooCommerce Checkout

跟風遠走 提交于 2019-11-29 12:46:31
I am trying to set the price of shipping rates to $0.00 if a checkbox in the checkout fields is checked. Current Attempt: function no_shipping_for_own_ups($rates,$package) { foreach ($rates as $rate) { //Set the price $rate->cost = 0; } return $rates; } function woo_add_cart_ups_y_n_fee( $cart ){ if ( ! $_POST || ( is_admin() && ! is_ajax() ) ) { return; } if ( isset( $_POST['post_data'] ) ) { parse_str( $_POST['post_data'], $post_data ); } else { $post_data = $_POST; } if (isset($post_data['billing_ups_yn'])) { add_filter( 'woocommerce_package_rates','no_shipping_for_own_ups', 99, 2 ); } }

Remove shipping Flat Rate method for particular Category in WooCommerce 2.6 and 3+

人盡茶涼 提交于 2019-11-29 12:13:02
I need help in woocommerce shipping options, I want to hide flat rate for a particular product category, where I only want to show local delivery or local pickup options. For all others categories all options should work. I have try to do it with that code (added in function.php file of my theme): function cart_has_product_with_orange_cats() { global $woocommerce; $product_in_cart = false; // start of the loop that fetches the cart items foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { $_product = $values['data']; $terms = get_the_terms( $_product->id, 'product_cat' );

How can i access current woocommerce order shipping method id?

青春壹個敷衍的年華 提交于 2019-11-29 03:02:51
问题 I have found method $order->get_shipping_method() to access the name, but i want to retrieve the id instead of name? 回答1: thought i'd share how I solved this if someone runs into the same problem as me. I have WC_Order in the $order variable. $order->get_items( 'shipping' ); This gives me an array with name, type, method_id, cost and taxes. 回答2: $shipping_method = @array_shift($order->get_shipping_methods()); $shipping_method_id = $shipping_method['method_id']; 来源: https://stackoverflow.com

Disable shipping method based on chosen payment method in Woocommerce

筅森魡賤 提交于 2019-11-28 14:17:58
I need to disable specific shipping method if user selected payment "Cash on Delivery". The problem is that the following code works only if I reset WooCommerce transients each time and refresh. It doesn't work on user selection back and forth. add_filter( 'woocommerce_package_rates', 'alter_shipping_methods', 100 ); function alter_shipping_methods( $rates ) { $chosen_gateway = WC()->session->chosen_payment_method; // If payment is Cash on delivery remove specific shipping if($chosen_gateway == 'cod') { foreach ( $rates as $rate_id => $rate ) { if ( $rate->label === 'Hrvatska pošta' ) { unset(

Remove “(optional)” text from checkout fields in Woocommerce 3.4+

若如初见. 提交于 2019-11-28 11:35:57
I was previously using this answer to hide checkout fields based on chosen shipping method, it worked fine until an update (3.4.2 current version) I think not sure what has changed but it doesn't work as intended anymore. Previously when local pickup was chosen some fields were hidden and made optional and when delivery was chosen it would show those fields again all via dynamically without reloading the page. Now it shows and hides the fields as required however, when delivery is chosen it is showing the correct fields marked as mandatory but also has the (optional) sign next to it and it

Insert a custom total row on cart and checkout totals in Woocommerce

不羁的心 提交于 2019-11-28 10:08:28
问题 In woocommerce, I have successfully managed to add a custom field to a Woocommerce simple product and display that value on the additional info tab on a product page. Now I am totally lost with the final piece of my jigsaw trying to insert a total row in cart and checkout pages with for the total calculated volume. The custom field is to store the volume in m3 of a furniture item. When a client adds an item to the basket I would like to calculate the total m3 of the shipment by adding the

Get orders shipping method details in WooCommerce 3

南楼画角 提交于 2019-11-28 07:48:31
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. 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); // Iterating through order shipping items foreach( $order->get_items( 'shipping' ) as $item_id => $shipping_item

Remove shipping Flat Rate method for particular Category in WooCommerce 2.6 and 3+

狂风中的少年 提交于 2019-11-28 05:53:01
问题 I need help in woocommerce shipping options, I want to hide flat rate for a particular product category, where I only want to show local delivery or local pickup options. For all others categories all options should work. I have try to do it with that code (added in function.php file of my theme): function cart_has_product_with_orange_cats() { global $woocommerce; $product_in_cart = false; // start of the loop that fetches the cart items foreach ( $woocommerce->cart->get_cart() as $cart_item

Disable shipping method based on chosen payment method in Woocommerce

两盒软妹~` 提交于 2019-11-27 19:33:43
问题 I need to disable specific shipping method if user selected payment "Cash on Delivery". The problem is that the following code works only if I reset WooCommerce transients each time and refresh. It doesn't work on user selection back and forth. add_filter( 'woocommerce_package_rates', 'alter_shipping_methods', 100 ); function alter_shipping_methods( $rates ) { $chosen_gateway = WC()->session->chosen_payment_method; // If payment is Cash on delivery remove specific shipping if($chosen_gateway