Forum

Thread tagged as: Question, Shop

Change shipping price based on location set on cart page

I'm trying to set up a shop with one shipping method for UK but with different shipping price for locations that the price needs to be different eg. Jersey, Guernsey etc

I need the customer to be able to select their location from a drop down list on the cart page, then the price for shipping changes along with the total for the order.

Similar to what James is asking here: https://forum.grabaperch.com/forum/10-21-2016-shop-shipping-zones

If I use the tag below and change the location which has a different price, the cart doesn't update the shipping price.

perch_shop_location_form();

Any ideas how I would do this please?

Mark Watts

Mark Watts 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

So are you saying that when you change location, the cart needs to recalculate the shipping?

Yes please.

I have the zones setup and if I select one from the dropdown a la 'location form' click the OK button it does a page refresh but doesn't update the Shipping cost.

Drew, any ideas on this please?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, it's something we're looking into.

Drew McLellan

Drew McLellan 2638 points
Perch Support

To be clear - the location form sets the tax location. It's the shipping address that sets the shipping costs. Are you expecting those two to be the same? They're actually two different things.

I think maybe my confusion has come from me reading your answer to the other thread I mentioned, where you said about perch_shop_location_form(). Not expecting them to be the same just trying to get it working as mentioned here:

https://docs.grabaperch.com/addons/shop/shipping/
In the Price to customer section, you can specify the price the customer is charged for the shipping method according to the shipping zone. Each shipping zone is listed, along with an available checkbox to activate and deactivate the shipping method for the specified zone.

Added this to the cart page:

    // Show the country list
    perch_shop_registration_form([
        'template' => 'cart/set_delivery_location.html'
    ]);

and this is the custom template:

<perch:form id="register" method="post" app="perch_shop">

    <h2>Set delivery location</h2>

    <fieldset>
        <legend>Choose from available delivery areas:</legend>
        <div>
            <perch:label for="country">Country</perch:label>
            <perch:input type="select" options="<perch:shop id="country_list" />" value="236" id="country" label="Country" />
        </div>

    </fieldset>
        <div>
            <perch:input type="submit" value="OK!" />
            <perch:input type="hidden" id="r" />
        </div>

</perch:form>

I just need a list of available shipping zones eg. UK, Guernsey, Jersey etc then once one is selected the shipping price changes accordingly. Only one delivery method at this stage. But I don't want to show every country just the places we will deliver to… for some reason I can't uncheck to disable any countries from the list either?

Does that make sense?

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's currently done by setting the delivery address. The zone is then automatically chosen based on that address.

OK I've tried to just list the country list part of the delivery address form on the cart page, but this still doesn't update the shipping price. This is crucial to the project happening, please could you give me some code guidance to get this working? I'm sure this would be beneficial to others as well. Would really appreciate your help here.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you on the current version of Shop?

Was on 1.2.1 now 1.2.2 :o) and 3.0.8 perch runway running locally

PHP 5.5.9-1ubuntu4.21 is up to date
 MySQL 5.5.55-0ubuntu0.14.04.1 is up to date
 Image processing available
 File upload size is low. You can only upload files up to 2M.
Summary information

Perch Runway: 3.0.8, PHP: 5.5.9-1ubuntu4.21, MySQL: 5.5.55, with PDO
Server OS: Linux, apache2handler
Installed apps: content (3.0.8), assets (3.0.8), categories (3.0.8), perch_shop_orders (1.2.2), perch_shop_products (1.2.2), perch_shop (1.2.2), perch_members (1.6.2)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_members', 'perch_shop', ); ?>
PERCH_LOGINPATH: /admin
PERCH_PATH: /var/www/siteurl/admin
PERCH_CORE: /var/www/siteurl/admin/core
PERCH_RESFILEPATH: /var/www/siteurl/admin/resources
Image manipulation: GD
PHP limits: Max upload 2M, Max POST 8M, Memory: 128M, Total max file upload: 2M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
HTTP_HOST: siteurl
DOCUMENT_ROOT: /var/www/siteurl/
REQUEST_URI: /admin/core/settings/diagnostics/
SCRIPT_NAME: /admin/core/settings/diagnostics/index.php

This is the order flow I currently have working (except changing shipping cost based on country/zone selected):

Order flow:
-----------

1.  Add to cart (goes to cart)
2.  Cart shows items ordered & Set Country (zone) from drop down list
4.  Country (zone) selection made from drop down list Click OK or reload on selection which sets/updates the delivery price according to Zone on the cart page
5.  Continue to Checkout page which has mini cart showing ordered products and all costs
6.  Checkout as guest with passwordless option (they can set a password and account on order completion if desired)
7.  Checkout displays both Billing & Shipping address options (Shipping address optional) continue button takes you to step 2 which confirms all the order details and delivery/shipping address.  Pay with card button brings up Stripe payment popup.
8.  Pay now button & stripe form redirects to:
-   Payment success or fail url /shop/payment/status

    Success message
    Option to create account
    Re-display order

    or

    Failure message 

-   Payment success or fail url /shop/payment/cancelled

    Cancelled message

If they choose to enter a password to create an account, then need to show account created success message or redirect to a page that says the same.

-   Redirect message for account created
Drew McLellan

Drew McLellan 2638 points
Perch Support

To confirm, it's still an issue with the update? We made some changes around this in the newest version.

Yes still an issue. But I'm not totally sure that I'm using the right code?

in cart.php:

perch_shop_registration_form([
'template' => 'cart/set_delivery_location.html',
]);

perch_shop_cart();

in custom template set_delivery_location.html:

<perch:form id="order_address" method="post" app="perch_shop">

    <h2>Set delivery location</h2>

    <fieldset>
        <legend>Choose from available delivery areas:</legend>
        <div>

            <perch:label for="country">Country</perch:label>
            <perch:input type="select" options="<perch:shop id="country_list" />" value="236" id="country" label="Country" />

        </div>

    </fieldset>
        <div>
            <perch:input type="submit" value="OK!" />
            <perch:input type="hidden" id="r" />
        </div>

</perch:form>

It displays ALL countries I select Guernsey (which is more expensive than the UK) click ok page refreshes but no price change on the shipping price displayed in the cart. I also can't disable all the countries except the ones we will deliver too.

Drew, I've had to change setup now to get the project moved forward, I've moved the shipping cost code now from Cart to Checkout after the address input and the shipping price based on zone updates whichever zone is selected :o) Just would of been nice if it could of been done upfront at Cart level. Thanks for your help anyway.