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

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
v:2.0:shipping:custom_code [2020/01/07 04:45]
adam [Free shipping based on a coupon]
v:2.0:shipping:custom_code [2020/05/28 16:09] (current)
marija [Category Settings]
Line 7: Line 7:
 <wrap tip>​**This custom code runs serverside,​** not client-side.</​wrap>​ Yes, it's javascript, but this javascript doesn'​t output to the browser. Instead, it's run serverside in Node.js (in a separate environment per store), so you can put private logic (such as coupon codes) in the code. <wrap tip>​**This custom code runs serverside,​** not client-side.</​wrap>​ Yes, it's javascript, but this javascript doesn'​t output to the browser. Instead, it's run serverside in Node.js (in a separate environment per store), so you can put private logic (such as coupon codes) in the code.
  
 +===== Category Settings =====
 +You'll need to set each [[https://​admin.foxycart.com/​admin.php?​ThisAction=ManageProductCategories|Category]] where you want the Custom Shipping Code to apply to //Shipped using live shipping rates//. You can do this after applying the custom shipping code to your shipping settings if you're not using live shipping rates already.
 ===== Enabling Custom Shipping Code ===== ===== Enabling Custom Shipping Code =====
  
Line 92: Line 94:
 </​code>​ </​code>​
  
 +==== Restricting shipping to only a specific set of postcodes ====
  
 +This example can be used to prevent customers from being able to complete the checkout if they don't have a shipping address within a specific set of postcodes. The ''​allowed_postcodes''​ array can be updated to include as many postcodes as needed. If a customer has a shipping address that doesn'​t have a matching postcode, they will instead see an error.
 +
 +<code javascript>​
 +const allowed_postcodes = [55115, 55116];
 +const postal_code = cart['​_embedded'​]['​fx:​shipment'​]['​postal_code'​];​
 +
 +if (allowed_postcodes.includes(postal_code)) {
 +    rates.add(10001,​ 10, '',​ '​Standard Shipping'​);​
 +} else {
 +    rates.error('​Sorry,​ we are not currently able to ship to your location'​);​
 +}
 +</​code>​
 ==== Hiding specific shipping rates depending on the shipping state ==== ==== Hiding specific shipping rates depending on the shipping state ====
  
Line 132: Line 147:
  
 This example would allow free shipping if a coupon with a code of ''​freeshipping''​ was present, or one that had a suffix of ''​-fs'',​ like ''​mycode-fs''​ or ''​h3Sif4yg-fs''​ This example would allow free shipping if a coupon with a code of ''​freeshipping''​ was present, or one that had a suffix of ''​-fs'',​ like ''​mycode-fs''​ or ''​h3Sif4yg-fs''​
 +
 +If you don't want to give a discount for the products and only free shipping, your coupon can be set to all the default settings with a ''​coupon details''​ string of ''​0-0''​.
  
 <code javascript>​ <code javascript>​
Line 236: Line 253:
 If you're needing to get rates from other providers that Foxy doesn'​t currently support, then using a third-party service like [[https://​goshippo.com/​|GoShippo]] can be a great option. We support fetching their rates through the custom shipping code feature, and you can see details on setting that up on the following page: If you're needing to get rates from other providers that Foxy doesn'​t currently support, then using a third-party service like [[https://​goshippo.com/​|GoShippo]] can be a great option. We support fetching their rates through the custom shipping code feature, and you can see details on setting that up on the following page:
  
-[[v:​2.0:​shipping:​custom_code:​goshippo|Fetching ​Shipping Rates from GoShippo]]+[[v:​2.0:​shipping:​custom_code:​goshippo|Fetching ​shipping rates from GoShippo]] 
 + 
 +==== Calculate flat rate shipping based on distance ==== 
 + 
 +For stores that want to calculate a flat rate shipping cost based on the distance, rather than using a live rate provider like USPS, FedEx or UPS, this approach can use the Google Maps API to calculate the distance between the store address and the customers. 
 + 
 +[[v:​2.0:​shipping:​custom_code:​google_maps_distance|Calculating flat rate shipping by distance]]

Site Tools