This is the documentation for LemonStand V1, which has been discontinued. You can learn more and upgrade your store here.

LemonStand Version 1 Has Been Discontinued

This documentation is for LemonStand Version 1. LemonStand is now offered as a cloud-based eCommerce platform.
You can try the new LemonStand and learn about upgrading here.

Implementing a Ship to Same Billing Address Feature

LemonStand checkout API allows you to add the "Ship to the billing address" checkbox to the Billing Information checkout step. If this checkbox is checked, LemonStand will copy customer's billing address to the shipping address and skip the Shipping Information step. The implementation described below is suitable for the AJAX-based checkout.

Adding the checkbox

First, add the "Ship to the billing address" checkbox to the Billing Information checkout step. In the demo store implementation this step is defined in the shop:checkout_billing_info partial. Checkbox code example:

<input type="checkbox" name="ship_to_billing_address" value="1"/>
Ship to the billing address

Changing the default AJAX handler on the Next button

We are going to use a custom AJAX handler for processing the Next button click on the Billing Information checkout step. Please replace the on_action event handler in the Next button onclick attribute. In this example we will name the custom AJAX handler "on_process_billing_address". Example:

<input ... onclick="return $(this).getForm().sendRequest('on_process_billing_address', {update:{'checkout_page': 'checkout_partial'}})"/>

Add the custom AJAX handler

Last step is defining the custom AJAX handler (on_process_billing_address). The handler should be defined on the AJAX tab of the Checkout page (a page which uses the shop:checkout action). Handler code: 

function on_process_billing_address($controller, $page, $params)
{
  // Call the default action handler
  $controller->action();

  // If the checkbox is checked,
  // copy billing address to shipping address
  // and move to the next step

  if (post('ship_to_billing_address'))
  {
    Shop_CheckoutData::copy_billing_to_shipping();
  
    $_POST['skip_to'] = 'shipping_method';
    $controller->action();
  }
}

Next: How to Simplify the Checkout Process
Previous: How to Use Partials Instead of Flash Messages
Return to Tips and Tricks