Documentation You are here: start » v » 2.0 » shipping

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
v:2.0:shipping [2023/07/12 14:05] – [Custom Shipping Endpoint] adamv:2.0:shipping [2023/07/12 14:05] (current) – [Custom Shipping Code] adam
Line 172: Line 172:
 [[v:2.0:shipping:custom_code|Review this page for more details]] on configuring the Custom Shipping Code option for your store. [[v:2.0:shipping:custom_code|Review this page for more details]] on configuring the Custom Shipping Code option for your store.
  
 +==== Passing custom fields to the custom shipping endpoint ====
 +
 +By default - any custom session attributes currently in the customers session will be included in the payload within the ''fx:custom_fields'' node. This includes anything added to the cart session using ''h:'' prepended before the attribute in an add to cart.
 +
 +Sometimes though you need to capture information from a customer on the checkout related to the shipping, such as whether a signature is required on delivery, which affects the rates calculated on your custom endpoint. To do that, you can add [[v:2.0:checkout#adding_custom_checkout_fields|custom checkout fields]] to your store, and add a ''data-fc-shipping-custom-field'' data attribute to the form elements. Whenever any fields with that data attribute are changed, it will trigger the shipping rates to the refreshed, including those values in the payload sent to your endpoint.
 +
 +<code html>
 +<!-- Checkbox -->
 +<input type="checkbox" id="sign_on_delivery" name="sign_on_delivery" value="Yes" {% if sign_on_delivery == "Yes" %}checked{% endif %} data-fc-shipping-custom-field>
 +<label for="sign_on_delivery">Sign on Delivery?</label>
 +
 +<!-- Radio inputs -->
 +<input type="radio" id="lift_required_yes" name="lift_required" value="Yes" {% if lift_required == "Yes" %}checked{% endif %} data-fc-shipping-custom-field>
 +<label for="lift_required_yes">Include a lift</label><br/>
 +<input type="radio" id="lift_required_no" name="lift_required" value="No" {% if lift_required == "No" %}checked{% endif %} data-fc-shipping-custom-field> <label for="lift_required_no">Don't include a lift</label>
 +
 +<!-- Text input -->
 +<input type="text" id="message" name="message" value="{{ message }}" data-fc-shipping-custom-field>
 +
 +<!-- Select options -->
 +<select name="pickup_location" data-fc-shipping-custom-field>
 +  <option value=""></option>
 +  <option value="factory">Factory</option>
 +  <option value="store">Store</option>
 +</select>
 +</code>
 +
 +If a value is already present in the cart session, and a custom checkout field shares the same name - the custom checkout field will overwrite the existing custom field in the session when sent to the custom shipping endpoint.
 +
 +If needed, you can also pass custom fields to the shipping endpoint using javascript and [[v:2.0:javascript|our events]], specifically ''cart-shipping-options-update'' and ''checkout-shipping-options-update''. Updates made by these events will overwrite any existing attributes already in the session, but will be overwritten by any matching custom checkout fields.
 +
 +<code javascript>
 +FC.client.on("checkout-shipping-options-update", function(params) {
 + params.custom_fields = { my_custom_attr: true };
 +});
 +</code>
 ==== Handling Fees ==== ==== Handling Fees ====
 Handling fees, like flat rates, are configured per category, but can be applied in a few different ways: Handling fees, like flat rates, are configured per category, but can be applied in a few different ways:

Site Tools