• Resolved Eric Mueller

    (@pnoeric)


    Hi, I have created a custom shipping method for delivery for my product – i.e. on checkout, you can choose a shipping choice like “Deliver Monday morning 8-12,” “Deliver Tuesday afternoon 12-4” etc.

    Now I want to give my users a coupon and offer free shipping with the coupon.

    The current Woo coupon functionality for free shipping requires that you add a “free shipping” shipping method. However, the free shipping method in Woo doesn’t let me do the custom delivery times that I need to do.

    What will work better is for me to change my custom shipping method code, and if the user is granted free shipping with a coupon, I can just change the price to 0.

    What hooks/code should I use to accomplish this? I don’t need detailed line-by-line code ?? but some sense of the best way to approach this would be great. I have searched the Woo docs at length but can’t find anything to help me with this.

    Any guidance/direction would be greatly appreciated.

    You can see a sample of my custom shipping method on this page, btw – just add a product to the cart, and on the cart page, try postal code “8001”… then you can play with the shipping choices there. https://df-food.ch

    thanks,
    Eric

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Neat idea and good question! This is a fairly complex development topic, so I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Slack Community as a great place for development questions:
    https://woocommerce.com/community-slack/

    Thread Starter Eric Mueller

    (@pnoeric)

    Hi Hannah, thanks. It ended up being pretty easy — I used code like this in my functions.php

    // do we have a coupon that gives free shipping?
    global $woocommerce;
    $all_applied_coupons = $woocommerce->cart->get_applied_coupons();
    if ( $all_applied_coupons ) {
    	foreach ( $all_applied_coupons as $coupon_code ) {
    		$this_coupon = new WC_Coupon( $coupon_code );
    		if ( $this_coupon->get_free_shipping() ) {
    			$freeshipping ++;
    		}
    	}
    }

    Thanks,
    Eric

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Hey there Eric,

    I’m glad you solved it – thanks for coming back and sharing the solution!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Supporting free shipping with custom shipping method’ is closed to new replies.