-
-
Save gedex/0e444c1026604416ba8cad8ebaf4be6e to your computer and use it in GitHub Desktop.
<?php | |
add_filter( 'woocommerce_distance_rate_shipping_rule_cost_distance_shipping', function( $rule_cost, $rule, $distance, $package ) { | |
$order_total = $package['contents_cost']; | |
if ( $order_total > 100 && $distance <= 5 ) { | |
$rule_cost = 0; | |
} | |
return $rule_cost; | |
}, 10, 4 ); |
I think this is exactly what I need, but I want to use the woocommerce_distance_rate_shipping_rule_cost_quantity_shipping
filter. Can you tell me what I need to get the quantity? $package['contents_cost']
would need to change to something like $package['contents_quantity'];
is that correct? Where can I find what attributes are in the $package
array?
Hello. I'm interested in purchasing the WooCommerce Distance Rate Shipping plugin. I have a condition to make, would it be possible using to have this scenario:
Delivery from restaurant:
1-3 miles & 20 pounds or above in basket = free delivery
1-3 miles & less than 20 pounds = 2.50 for delivery
1-3 miles & less than 12 pounds = no delivery
3.1-4.0 & 20 pounds or above in the basket = 1 pound delivery
3.1-4.0 & less than 20 pounds = 3.50 for delivery
3.1-4.0 & less than 12 pounds = no delivery
Is this doable in this plugin? If there needs to be a custom code, would you provide an example here? Thank you
Great! When I use this, and when the purchase is actually more than $100 and within 5 miles of distance, in the shipping section of checkout table on checkout page, it says only "Local pickup". Do you know why this is happening or how I can fix this?
Awesome! With this example, I was able to figure out distance and weight conditions using the cart contents weight variable. I needed to do multiple zones with dual rates based upon weight and this seems to work well. Oh, it seems that only one shipping zone (All Zones) is needed, even for multiple zones (custom code does the multiple zones work). I then added Distance Rate as a shipping method within it (you can limit zip codes here as well). Within the Distance Rate shipping method, I added a single distance rule with default values (I guess it just needs to be there for this custom code to work). I also added my shop address here.
<?php
add_filter( 'woocommerce_distance_rate_shipping_rule_cost_distance_shipping', function( $rule_cost, $rule, $distance, $package ) {
$cart_weight = WC()->cart->cart_contents_weight;
if ( $cart_weight <= 12000 && $distance <= 3 ) {
$rule_cost = 40; // Zone 1 - Rate 1
} elseif ( $cart_weight > 12000 && $distance <= 3 ) {
$rule_cost = 45; // Zone 1 - Rate 2
} elseif ( $cart_weight <= 12000 && $distance > 3.1 && $distance <= 6 ) {
$rule_cost = 50; // Zone 2 - Rate 1
} elseif ( $cart_weight > 12000 && $distance > 3.1 && $distance <= 6 ) {
$rule_cost = 55; // Zone 2 - Rate 2
}
return $rule_cost;
}, 10, 4 );
Hello. I'm interested in purchasing the WooCommerce Distance Rate Shipping plugin. I have a condition to make, would it be possible using to have this scenario: Delivery from restaurant: 1-3 miles & 20 pounds or above in basket = free delivery 1-3 miles & less than 20 pounds = 2.50 for delivery 1-3 miles & less than 12 pounds = no delivery
3.1-4.0 & 20 pounds or above in the basket = 1 pound delivery 3.1-4.0 & less than 20 pounds = 3.50 for delivery 3.1-4.0 & less than 12 pounds = no delivery
Is this doable in this plugin? If there needs to be a custom code, would you provide an example here? Thank you
Is it possible?
Example scenario:
DRS 1.0.8 adds a bunch of new filters, including
woocommerce_distance_rate_shipping_rule_cost_distance_shipping
, to override rule cost when selected Condition is Distance. With above scenario, no need to set rule number 2 in the DRS table.The snippet above can be placed in your theme's
functions.php
or as a drop-in plugin.