• Resolved sandyaritaward

    (@sandyaritaward)


    Hello,

    I found php code to allow for a 5% discount on items that are picked up. However the code is adding the discount after the sub-total and TaxCloud won’t allow for negative prices after subtotal.

    Here’s the code I used:

    add_action( ‘woocommerce_cart_calculate_fees’, ‘custom_discount_for_pickup_shipping_method’, 10, 1 );
    function custom_discount_for_pickup_shipping_method( $cart ) {
    if ( is_admin() && ! defined( ‘DOING_AJAX’ ) )
    return;

    $percentage = 5; // <=== Discount percentage

    $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 = $cart->get_subtotal() * $percentage / 100;
    // Add the discount
    $cart->add_fee( __(‘Pickup discount’) . ‘ (‘ . $percentage . ‘%)’, -$discount );
    }
    }

    Any help/ideas would be greatly appreciated.

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Give a Discount to Local Pickup’ is closed to new replies.