PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Deduct delivery fee before adding Sales tax

  1. I have a form here:
    http://remingtontopsoil.com/order-online

    I recently added this code to automatically add VA sales tax to my order:
    http://pastie.org/2102201

    This code works. However the sales tax should not be charged on the delivery fee.

    So the tax is calculated like this:
    return total + (total * 0.05);

    Is there a way to identify the delivery fee field on my form, so that I can subtract it from the total before applying the sales tax? The field label on my form is "Delivery Fee by Zip Code". Would I use the field name or is there a way to get the field "id"?

    So can I change the code to something like this?
    return total - delivery fee by zip code;
    return total + (total * 0.05);
    return total + delivery fee by zip code;

    Posted 12 years ago on Wednesday August 17, 2011 | Permalink
  2. Hi remington,

    Give this a shot: http://pastie.org/2387558

    If it generates a JS error, leave it and report back and I can fine tune the snippet a bit.

    Posted 12 years ago on Wednesday August 17, 2011 | Permalink
  3. David,

    Okay added this code, no JS error. Testing it on this page:
    http://remingtontopsoil.com/order-online

    I select a product and enter a quantity, the Order Total reflects the correct amount including the sales tax. But when I go to the bottom, and select the delivery fee from the drop-down, it's not added to the Order Total.

    Here is my code:

    var deliveryFee = jQuery('#input_2_20').val().split('|')[1];
    total -= deliveryFee;

    return total + (total * 0.05);
    }

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  4. Oops. Try this:

    http://pastie.org/2391965

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  5. AWESOME...that did it!!!

    Thank you very much. Great support with quick turn-around.

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  6. So sorry, I spoke too soon!! I placed an order with the order total of $81.50. The Order Total is correct on this page:

    http://remingtontopsoil.com/order-online

    One item $30.00 + 5% sales tax = $31.50 + $50 delivery (Total $81.50)

    However, when I look in the WP admin panel and review the entries, the order shows sales tax = $4.00 and order total of $84.00.

    So the sales tax is correctly only on the products on the order form. However the entries and the email I receive, still have tax charged on items and delivery fee.

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  7. Hi Reminginton,

    You would need to apply the same concept used to subtract the delivery fee from in the javascript to the code run in the gform_product_info_57 hook. The delivery fee should be part of the $product_info array.

    Posted 12 years ago on Thursday August 18, 2011 | Permalink
  8. HI David,

    Okay so I changed the code in the gform_product_info_57 hook by adding the line that refers to the delivery fee. I'm trying to subtract it from the total that it returns.

    $total += floatval($products["shipping"]["price"]);
    $total -= floatval($products["Delivery Fee by Zip Code"]["price"]);
    return $total;
    }

    But it's not working. Am I referring to the delivery fee element of the $product_info array correctly?

    Thanks for your help.

    Posted 12 years ago on Monday August 22, 2011 | Permalink
  9. David,

    I figured this out. Thanks again for all your help.

    Posted 12 years ago on Tuesday September 6, 2011 | Permalink
  10. Pandonym
    Member

    Hi,

    I have a similar issue. I want to give a discount on some products if a special product (or option) is selected. The discount should only apply to the other options (or products) and not for the rest.

    I think this code here is the right one, but I don't understand it :-)

    Can you please help me?

    Posted 12 years ago on Tuesday October 18, 2011 | Permalink
  11. Pandonym
    Member

    I reword it. I want to add a discount or tax just to a price-option if a special product is chosen.

    How can I achieve that?

    Posted 12 years ago on Thursday October 20, 2011 | Permalink
  12. @Pandonym, please start a new topic for your issue. Thank you.

    Posted 12 years ago on Thursday October 20, 2011 | Permalink