Today I’ll show you how to give a discount to local pickup in your Woocommerce store. The solution is really easy and it will take a only couple of minutes to implement. So, lets jump in.
Why Should You Give a Discount to Local Pickup Shipping Method?
Probably you have a question? Why would I give a discount if someone comes to pick to product up? Well, two reasons:
- You have a small shop and therefore you have no time to hassle with the shipments all the time. Therefore, it would be much easier for you if the customer would come to the shop to pick the product up. Because…
- …this way you can offer the customer up-sells, cross-sells etc. It is a handy method to make your customer to visit your shop.
So, to motivate your customers to choose a local pickup shipping method you may want to consider give them a small discount.
How to Give a Percentage Discount to Local Pickup in Woocommerce?
Just grab this code here below and paste it to your functions.php file. Or better yet, use Code Snippets plugin which allows you to add custom functions without the need to modify your theme files. Pay attention though that this example adds a percentage based discount to your Woocommerce checkout.
Couple of things to point out:
1) Set your percentage in the row 5. In the example 0.15 means 15%. If you want to give a 5% discount, set it to 0.05
2) Row 6 has “Discount added” text which will be shown under the Local Pickup shipping method if the method is selected. See the screenshot below. So, change this text if needed.
// Add Percentage Discount to Local Pickup in Woocommerce
function local_pickup_discount( $cart ) {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_no_ajax = $chosen_methods[0];
if ( 0 === strpos( $chosen_shipping_no_ajax, 'local_pickup' ) ) {
$discount = $cart->subtotal * 0.15; // Set your percentage. This here gives 15% discount
$cart->add_fee( __( 'Discount added', 'yourtext-domain' ) , -$discount ); // Change the text if needed
}
}
add_action( 'woocommerce_cart_calculate_fees', 'local_pickup_discount');
Now, if everything is correctly added then this shpuld be the end result.
How to Add a Fixed Amount Discount to Local Pickup in Woocommerce?
But what if you need to add a fixed amount discount to your local pickup shipping method? If so, then use this snippet here below.
Couple of things to point out:
1) Set your fixed amount in the row 9. In the example 5 means 5 euros. If you want to give a 10 euros discount then change this number accordingly.
2) Row 20 has “Pickup discount” text which will be shown under the Local Pickup shipping method if the method is selected. So, change this text if needed. Also, if you need to change the currency sign then it’s in the same row.
// Add Fixed Amount Discount to Local Pickup in Woocommerce
add_action( 'woocommerce_cart_calculate_fees', 'local_pickup_fixed_discount', 10, 1 );
function local_pickup_fixed_discount( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// Only on checkout page
if ( is_checkout() ) {
$amount = 5; // <=== Set your Discount amount
$chosen_shipping_method_id = WC()->session->get( 'chosen_shipping_methods' )[0];
$chosen_shipping_method = explode(':', $chosen_shipping_method_id)[0];
// Only for Local pickup chosen shipping method
if ( strpos( $chosen_shipping_method_id, 'local_pickup' ) !== false ) {
// Calculate the discount
$discount = $amount;
// Add the discount
$cart->add_fee( __('Pickup discount') . ' (' . $amount . '€)' , -$discount );
}
}
}