Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ttea

    (@ttea)

    Sure Christine,

    Not a problem. what the author showed me was I needed to create two scenarios and link them as “or”.

    So the FIRST criteria (coupon not used) was:
    a. Country ‘equals’ (your country of choice)
    b. Zip Code ‘equals or greater than’ (this was needed for the Aus Post API, so might be optional for you)
    c. Coupon ‘DOES NOT EQUAL’ (name of the coupon in question)
    d. Cart Subtotal ‘equals or greater than’ (the minimum for free shipping)

    Then you add another criteria as “OR” and it should be:
    a. Country ‘equals’ (your country of choice)
    b. Zip Code ‘equals or greater than’ (this was needed for the Aus Post API, so might be optional for you)
    c. Coupon ‘EQUALS’ (name of the coupon in question)
    d. Cart Subtotal ‘equals or greater than’ (add the increased amount needed to ensure the total is allowed free shipping)

    In my case I wanted free shipping for $80 orders or above and I have a 20% off coupon.
    So the first criteria subtotal was $80.00
    The second criteria subtotal needed to be $100.00, which gives $80.00 after the coupon is used.

    Hope this helps!
    ttea

    Thread Starter ttea

    (@ttea)

    Hi Jeroen,
    Thanks for the quick reply!

    NEW VS PREVIOUS VERSION OF PLUGIN:
    First off, I am also using the Australia Post Shipping API, which actually overrides the ‘free shipping’ in woocommerce as the woo version only goes by country and the AusPost API also checks post/zip code and then stops the free shipping.

    Your plugin is awesome as it actually allows the extra criteria of a post/zip code along with a cart subtotal, which now allows me to give free shipping when customers when they ‘calculate shipping”, so BIG THANKS!

    The prior version kept ‘free shipping’ appearing in the shipping area as text and never allowed any other shipping method even when the customer ‘calculate shipping’ within Australia.

    The new version displays ‘free shipping’ as one of the possible shipping options along with the AusPost shipping methods in the drop down when the customer qualifies for free shipping. I don’t want a customer to accidentially select a pay option.

    CODE – TRYING TO CALCULATE FREE SHIPPING BASED ON CART TOTAL AFTER COUPON APPLIED:
    Woocommerce and your plugin both use Cart Subtotal, which means when a coupon is applied a customer still gets free shipping even though the order is brought below the minimum amount by the coupon.

    I have been trying to update the code below to work with your plugin which would calculate free shipping based on the cart total instead:

    // WooCommerce Shipping Calculated after Coupon
    add_filter( 'Wafs_Free_Shipping_Method_is_available', 'advanced_free_shipping', 10, 2 );
    
    function advanced_free_shipping( $is_available, $package ) {
    if ( WC()->cart->prices_include_tax )
    $total = WC()->cart->cart_contents_total + array_sum( WC()->cart->taxes );
    else
    $total = WC()->cart->cart_contents_total;
    
    $total = $total - ( WC()->cart->get_order_discount_total() + WC()->cart->get_cart_discount_total() );
    
    // You can hardcode the number or get the setting from the shipping method
    $shipping_settings = get_option('advanced_free_shipping_settings');
    $min_total = $shipping_settings['min_amount'] > 0 ? $shipping_settings['min_amount'] : 0;
    if ( 50 > $total ) {
    $is_available = false;
    }
    
    return $is_available;
    }
    
    // This basically recalculates totals after the discount has been added
    add_action( 'woocommerce_calculate_totals', 'change_shipping_calc' );
    function change_shipping_calc( $cart ) {
    
    $packages = WC()->cart->get_shipping_packages();
    
    // Calculate costs for passed packages
    $package_keys = array_keys( $packages );
    $package_keys_size = sizeof( $package_keys );
    
    for ( $i = 0; $i < $package_keys_size; $i ++ ) {
    unset( $packages[ $package_keys[ $i ] ]['rates'] );
    
    $package_hash = 'wc_ship_' . md5( json_encode( $packages[ $package_keys[ $i ] ] ) );
    
    delete_transient( $package_hash );
    }
    
    // Calculate the Shipping
    $cart->calculate_shipping();
    
    // Trigger the fees API where developers can add fees to the cart
    $cart->calculate_fees();
    
    // Total up/round taxes and shipping taxes
    if ( $cart->round_at_subtotal ) {
    $cart->tax_total = $cart->tax->get_tax_total( $cart->taxes );
    $cart->shipping_tax_total = $cart->tax->get_tax_total( $cart->shipping_taxes );
    $cart->taxes = array_map( array( $cart->tax, 'round' ), $cart->taxes );
    $cart->shipping_taxes = array_map( array( $cart->tax, 'round' ), $cart->shipping_taxes );
    } else {
    $cart->tax_total = array_sum( $cart->taxes );
    $cart->shipping_tax_total = array_sum( $cart->shipping_taxes );
    }
    
    add_filter( 'woocommerce_table_rate_query_rates_args', 'filter_shipping_2', 10 );
    function filter_shipping_2( $arguments ) {
    if ( WC()->cart->prices_include_tax )
    $total = WC()->cart->cart_contents_total + array_sum( WC()->cart->taxes );
    else
    $total = WC()->cart->cart_contents_total;
    
    $total = $total - ( WC()->cart->get_order_discount_total() + WC()->cart->get_cart_discount_total() );
    
    $arguments['price'] = $total;
    
    return $arguments;
    }
Viewing 2 replies - 1 through 2 (of 2 total)