quitar plugin gratuito envios envio como php wordpress woocommerce checkout shipping

php - plugin - Envío gratuito en función del peso y del monto mínimo del carrito.



como quitar envio gratuito! prestashop (2)

Para envío gratis por encima de cierta cantidad, puede usar la opción incorporada de WooCommerce.

Para evitar el envío gratuito, si para algunos productos específicos, puede utilizar el siguiente fragmento.

add_filter(''woocommerce_package_rates'', ''hide_shipping_method_if_particular_product_available_in_cart'', 10, 2); function hide_shipping_method_if_particular_product_available_in_cart($available_shipping_methods) { global $woocommerce; // products_array should be filled with all the products ids // for which shipping method (stamps) to be restricted. $products_array = array( 101, 102, 103, 104 ); // You can find the shipping service codes by doing inspect element using // developer tools of chrome. Code for each shipping service can be obtained by // checking ''value'' of shipping option. $shipping_services_to_hide = array( ''free_shipping'', ); // Get all products from the cart. $products = $woocommerce->cart->get_cart(); // Crawl through each items in the cart. foreach($products as $key => $item) { // If any product id from the array is present in the cart, // unset all shipping method services part of shipping_services_to_hide array. if (in_array($item[''product_id''], $products_array)) { foreach($shipping_services_to_hide as & $value) { unset($available_shipping_methods[$value]); } break; } } // return updated available_shipping_methods; return }

Con WooCommerce, necesito tener envío gratis sobre una cantidad determinada de 250, excepto los productos pesados ​​que están incluidos en el carrito.

¿Alguien sabe lo que debería hacer?

Gracias.


Este código personalizado mantendrá el método de envío gratuito y ocultará otros métodos de envío cuando el monto del carrito sea de hasta 250 y si los productos no son pesados (menos de 20 kg aquí) ... Para no permitir el envío gratis para pedidos inferiores a 250, puede configurar esto en woocommerce (ver al final).

Primero, deberá asegurarse de que el peso esté establecido en cada producto pesado (para productos simples o variables (en cada variación). El subtotal del carrito aquí es Excluyendo impuestos (y puede cambiarlo a Impuestos incluidos fácilmente) .

Entonces aquí está esa función enganchada personalizada en woocommerce_package_rates filter hook:

add_filter( ''woocommerce_package_rates'', ''conditionally_hide_other_shipping_based_on_items_weight'', 100, 1 ); function conditionally_hide_other_shipping_based_on_items_weight( $rates ) { // Set HERE your targeted weight (here is 20 kg) <== <== <== <== <== $target_product_weight = 20; // Set HERE your targeted cart amount (here is 250) <== <== <== <== <== $target_cart_amount = 250; // For cart subtotal amount EXCLUDING TAXES WC()->cart->subtotal_ex_tax >= $target_cart_amount ? $passed = true : $passed = false ; // For cart subtotal amount INCLUDING TAXES (replace by this): // WC()->cart->subtotal >= $target_cart_amount ? $passed = true : $passed = false ; // Iterating trough cart items to get the weight for each item foreach(WC()->cart->get_cart() as $cart_item){ if( $cart_item[''variation_id''] > 0) $item_id = $cart_item[''variation_id'']; else $item_id = $cart_item[''product_id'']; // Getting the product weight $product_weight = get_post_meta( $item_id , ''_weight'', true); if( !empty($product_weight) && $product_weight >= $target_cart_amount ){ $light_products_only = false; break; } else $light_products_only = true; } // If ''free_shipping'' method is available and if products are not heavy // and cart amout up to the target limit, we hide other methods $free = array(); foreach ( $rates as $rate_id => $rate ) { if ( ''free_shipping'' === $rate->method_id && $passed && $light_products_only ) { $free[ $rate_id ] = $rate; break; } } return ! empty( $free ) ? $free : $rates; }

El código va en el archivo function.php de su tema hijo activo (o tema) o también en cualquier archivo de complemento.

Este código está probado y funciona para productos simples y variables ...

También deberá en la configuración de WooCommerce> Envío, para cada zona de envío y para el método de "Free Shipping" , su cantidad mínima de pedido: