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

Migrating to Custom Shipping Code

If you've had some custom needs for shipping in your Foxy 2.0 Store, then odds are that you're utilising one of the snippets available on our wiki. If that's you, we would highly recommend migrating from the existing snippet over to the new native custom shipping code functionality.

Below are some notes for moving over to the new functionality from some of the more common snippets.

If you have any questions about, or need help with migrating, your specific snippet set up, please get in contact with us and we'll be happy to help.

Live Rate Shipping Modification

Original Snippet

This snippet added the ability to modify the live rates that were returned from third-party carriers like USPS, FedEx and UPS, as well as add in custom rates too. As the new custom shipping code functionality is executed after any selected carriers for a store, and is passed those rates to begin with, you can peform the same functionality in the custom code.

Converting logic

While similar functions are supported, some changes are necessary to use the new chainable functions in the custom shipping code.

// Existing
FC.customLiveShipping.add(300, 4.99, 'PostBox', 'Local Delivery');
// New
rates.add(10300, 4.99, 'PostBox', 'Local Delivery');
 
// Existing
FC.customLiveShipping.hide('all');
FC.customLiveShipping.hide('FedEx');
// New
rates.hide();
rates.filter('FedEx').hide();
 
// Existing
FC.customLiveShipping.show('all');
FC.customLiveShipping.show('FedEx');
// New
rates.show();
rates.filter('FedEx').show();
 
// Existing
FC.customLiveShipping.update('all', '*2');
FC.customLiveShipping.update('Overnight', '+5');
FC.customLiveShipping.update('USPS Ground', null, null, 'Super Saver');
// New
rates.price('*2');
rates.filter('Overnight').price('+5');
rates.filter('USPS Ground').service('Super Saver');
 
// Existing
FC.customLiveShipping.remove('all');
FC.customLiveShipping.remove('FedEx');
// New
// Replaced with hide()
 
// Existing
FC.customLiveShipping.reset();
// New
rates.reset();

For details on how to access information about the customers address and cart, view the examples on the custom shipping code wiki page.

Migration steps

  1. Locate where you're including the snippet in your store, and copy it to a file on your computer as a backup. It will most likely be in your store's configuration on the “Add custom header and footer code to your templates” option, or included in your store's “cart include” template.
  2. Using the notes above, convert your custom shipping logic shown between the BEGIN CUSTOM SHIPPING LOGIC and END CUSTOM SHIPPING LOGIC lines to work with the new custom shipping code's javascript API.
  3. Remove the Live Rate Shipping Modification snippet from your store
  4. Enable the custom shipping code option as detailed here, and use your converted logic for the custom code

Flat Rate Shipping Modification

Original Snippet

This was a very common snippet which added the ability to specify custom flat rates for your store - whether that was a single cost you wanted to apply across the whole store, a specific cost based on the country of the customer, or multiple different rates based on varying conditions.

Converting logic

While similar functions are supported, some changes are necessary to use the new chainable functions in the custom shipping code.

// Existing
FC.customFlatRates.add(100, 4.99, 'PostBox', 'Local Delivery');
// New
rates.add(10100, 4.99, 'PostBox', 'Local Delivery');
 
// Existing
FC.customFlatRates.hide('all');
FC.customFlatRates.hide('FedEx');
// New
rates.hide();
rates.filter('FedEx').hide();
 
// Existing
FC.customFlatRates.show('all');
FC.customFlatRates.show('FedEx');
// New
rates.show();
rates.filter('FedEx').show();
 
// Existing
FC.customFlatRates.update('all', '*2');
FC.customFlatRates.update('Overnight', '+5');
FC.customFlatRates.update('USPS Ground', null, null, 'Super Saver');
// New
rates.price('*2');
rates.filter('Overnight').price('+5');
rates.filter('USPS Ground').service('Super Saver');
 
// Existing
FC.customFlatRates.remove('all');
FC.customFlatRates.remove('FedEx');
// New
// Replaced with hide()
 
// Existing
FC.customFlatRates.reset();
// New
rates.reset();
 
// Existing
FC.customFlatRates.error('Sorry, we can\'t ship to Canada');
// New
rates.error('Sorry, we can\t' ship to Canada');

For details on how to access information about the customers address and cart, view the examples on the custom shipping code wiki page.

Migration steps

  1. Locate where you're including the snippet in your store, and copy it to a file on your computer as a backup. It will most likely be in your store's configuration on the “Add custom header and footer code to your templates” option, or included in your store's “cart include” template.
  2. Using the notes above, convert your custom shipping logic shown between the BEGIN CUSTOM SHIPPING LOGIC and END CUSTOM SHIPPING LOGIC lines to work with the new custom shipping code's javascript API.
  3. Remove the Flat Rate Shipping Modification snippet from your store
  4. Enable the custom shipping code option as detailed here, and use your converted logic for the custom code
  5. For each category in your store that you want to use the custom shipping code, edit them from the “categories” section in your store's Foxy administration and set the delivery type to “Shipped using live shipping rates”. You will also need to specify a default weight for products in that respective category.

If you don't want to have the “weight” parameter shown for your products in the cart, this can be hidden from customers using an option found on the “configuration” page of your store's Foxy administration. Enable the option labelled “Customize Cart Display” and uncheck the option for “Show Product Weight”. Saving the updated configuration will hide the weight from the customer.

Remove days timeframe from USPS rates

Original Snippet

This is just a basic snippet that removes the “1-Day” and “2-Day” strings from USPS rate descriptions.

  1. Firstly, you'll want to remove the snippet from your store - wherever you've added it, most likely on the “configuration” page under “Add custom header and footer code to your templates”.
  2. Next you'll want to enable the custom shipping code option as detailed here, and review this example for the custom code you need.

Breaking large shipments into multiple smaller packages

Original Snippet

If your store had heavier products, this snippet is commonly used to break up orders into smaller packages to allow rates to be returned, before multiplying the rates by the number of packages.

This snippet also makes use of the Live Rate Shipping Modification snippet - but if all you're doing is accounting for the number of packages, and not making any other changes - you can use another new feature that was added recently.

To confirm that, review your custom snippet, and ensure that all that you are doing within the BEGIN CUSTOM SHIPPING LOGIC and END CUSTOM SHIPPING LOGIC lines is this:

FC.customLiveShipping.update('all', '*' + FC.customLiveShipping.custom_packages);

If there is other customLiveShipping calls you're making, you'll also need to review the migration notes for the Live Rate Shipping Modification snippet as detailed earlier on this page, in combination with the below.

To remove the overweight packages snippet:

  1. Remove the the snippet from your store - wherever you've added it, most likely on the “configuration” page under “Add custom header and footer code to your templates”.
  2. On your admin's “Shipping” page, at the bottom look for the option labelled “max package weight”, and set it to the largest package size that you support for your store. Any orders greater than that will be broken into multiple packages that are under this limit.

For more details on this new “max package weight” setting, check out this page.

Site Tools