Minimum Amount for Local Delivery – Working!
-
Hi. Has anyone had an idea where in we could put a minimum amount for the Local Delivery, same thing what Free Shipping does but with a delivery fee added?
I’d come across all the section in this forum (and other sites) but I think no one been able to sort this issue out. So, I tried doing it on my own, and yeah I know editing inside WooCommerce plugin is a bad idea. Because, we all know if they ever update the plugin everything we did will be gone and reset back to plugin default.
So, let’s get started.
We will be needing these files, make sure you have the latest core update.
– class-wc-shipping-free-shipping.php
– class-wc-shipping-local-delivery.phpFirst, open up both files on your favorite text/html editor. For class-wc-shipping-free-shipping.php, find and copy the following lines:
$this->enabled = $this->get_option( 'enabled' ); $this->min_amount = $this->get_option( 'min_amount', 0 ); $this->requires = $this->get_option( 'requires' );
Then open click on class-wc-shipping-local-delivery.php and paste them under function init(). Before and on top of the line add_action().
Heads up to class-wc-shipping-free-shipping.php again, find and copy the following lines:
'requires' => array( 'title' => __( 'Free Shipping Requires...', 'woocommerce' ), 'type' => 'select', 'default' => '', 'options' => array( '' => __( 'N/A', 'woocommerce' ), 'coupon' => __( 'A valid free shipping coupon', 'woocommerce' ), 'min_amount' => __( 'A minimum order amount (defined below)', 'woocommerce' ), 'either' => __( 'A minimum order amount OR a coupon', 'woocommerce' ), 'both' => __( 'A minimum order amount AND a coupon', 'woocommerce' ), ) ), 'min_amount' => array( 'title' => __( 'Minimum Order Amount', 'woocommerce' ), 'type' => 'price', 'placeholder' => wc_format_localized_price( 0 ), 'description' => __( 'Users will need to spend this amount to get free shipping (if enabled above).', 'woocommerce' ), 'default' => '0', 'desc_tip' => true ) );
Then paste them again on class-wc-shipping-local-delivery.php, under function init_form_fields().
Last, find and copy the lines from class-wc-shipping-free-shipping.php:
// Enabled logic $is_available = false; $has_coupon = false; $has_met_min_amount = false; if ( in_array( $this->requires, array( 'coupon', 'either', 'both' ) ) ) { if ( $coupons = WC()->cart->get_coupons() ) { foreach ( $coupons as $code => $coupon ) { if ( $coupon->is_valid() && $coupon->enable_free_shipping() ) $has_coupon = true; } } } if ( in_array( $this->requires, array( 'min_amount', 'either', 'both' ) ) && isset( WC()->cart->cart_contents_total ) ) { if ( WC()->cart->prices_include_tax ) $total = WC()->cart->cart_contents_total + array_sum( WC()->cart->taxes ); else $total = WC()->cart->cart_contents_total; if ( $total >= $this->min_amount ) $has_met_min_amount = true; } switch ( $this->requires ) { case 'min_amount' : if ( $has_met_min_amount ) $is_available = true; break; case 'coupon' : if ( $has_coupon ) $is_available = true; break; case 'both' : if ( $has_met_min_amount && $has_coupon ) $is_available = true; break; case 'either' : if ( $has_met_min_amount || $has_coupon ) $is_available = true; break; default : $is_available = true; break; }
Then paste them on class-wc-shipping-local-delivery.php under function is_available(). Before and on top of return apply_filters().
Save and upload class-wc-shipping-local-deliver.php on /plugins/woocommerce/includes/shipping/local-delivery folder.
Pros: It works like we want it. LD option won’t show up if the value is set to 2 or more (not including the right value/amount).
Cons: When the item value is set to 1. Local Delivery option shows up. Which I found it weird or maybe there’s still missing.
That’s it! Hope this helps. If there’s someone who could fix our the remaining issue, just post away! Cheers
Jhay
- The topic ‘Minimum Amount for Local Delivery – Working!’ is closed to new replies.