Hooks
The default behavior of the Quick Buy add-on is to replicate the standard checkout functionality of your CS-Cart store, including handling coupons, discounts, and available shipping methods.
If you want to customize the checkout experience specifically for customers using Quick Buy, you can leverage the programmatic hooks provided by this add-on to dynamically adjust the checkout form and behavior.
Customizing available shipping methods
The simpler_filter_delivery_option
hook allows you to modify the shipping methods available to customers using Simpler Checkout. This hook receives the resolved delivery options for the cart and allows you to modify or filter them as needed. It should return the updated delivery options.
Delivery options are structured as follows:
$delivery_option = [
'id' => '1', // shipping_method_id
'name' => 'Courier name',
'type' => 'DELIVERY'
];
Example: Removing a Shipping Method from Simpler Checkout The following example demonstrates how to remove a specific shipping method based on its name:
<?php
function fn_myaddon_simpler_filter_delivery_option(&$delivery_option) {
if (strpos($delivery_option['name'], 'Express') !== false) {
// remove this delivery option from the list
$delivery_option = null;
}
}
Example: Changing the Type of a Shipping Method
In this example, the type
of a shipping method is modified based on its ID:
<?php
function fn_myaddon_simpler_filter_delivery_option(&$delivery_option) {
if ($delivery_option['id'] == 6) {
// change delivery option type
$delivery_option['type'] = 'BOX_NOW';
}
}
Get Order & Invoice Data After Order Submit
This functionality allows you to retrieve order and invoice data right after an order is submitted through Quick Buy. You can use it to customize order handling, add notes, or interact with external systems that need invoice information.
Hook: simpler_submit_order
The simpler_submit_order
hook is triggered when an order is submitted through the Quick Buy process. This hook provides access to both the order and invoice data, allowing for any modifications or custom actions needed immediately after submission.
Parameters
The hook provides the following parameters in an array, allowing developers to directly manipulate and enhance the order data:
order
(Array, passed by reference): Contains detailed information about the submitted order. Developers can modify this data as required, such as appending notes or adjusting item details.order_request
(Array): An array containing additional data related to the order request, including customer details, items, and metadata.
Example Usage
Here’s an example of how to use the simpler_submit_order
hook in your add-on to add custom logic when a Quick Buy order is submitted:
<?php
use Tygh\Registry;
function fn_myaddon_simpler_submit_order(&$order, $order_request)
{
// Check if the order data is available
if (!empty($order)) {
// Check if the order request includes invoice information
if (isset($order_request['invoice']) && !empty($order_request['invoice'])) {
// Add invoice data to the order note for future reference
$order['notes'] .= "\nInvoice Data: " . json_encode($order_request['invoice']);
// Log the invoice information (optional)
fn_log_event('orders', 'add_note', [
'order_id' => $order['order_id'],
'invoice_data' => $order_request['invoice'],
]);
}
}
}
In this example, the simpler_submit_order
hook checks if invoice
data is included in the order request and appends it to the order notes. This can also be logged to the CS-Cart logs for tracking purposes.
Retrieve Box Now data upon order submission
For developers utilizing a custom Box Now module, the simpler_submit_order
hook offers a method to retrieve locker information associated with an order after submission.
Parameters
The hook provides the following parameters:
order
(Order object, passed by reference): The order object that represents the submitted order. Developers can modify the order data directly through this parameter.order_request
(Array): An array containing additional data related to the order request, which can be used for further custom processing or logic.
Example Usage
Below is an example demonstrating how to use the simpler_submit_order
hook within a module:
<?php
use Tygh\Registry;
function fn_myaddon_simpler_submit_order(&$order, $order_request)
{
// Check if the order data is available
if (!empty($order)) {
// Verify if the order_request is not empty
if (!empty($order_request)) {
// Ensure that the shipping method ID is set to 'BOX_NOW'
if (isset($order_request['shipping_method_id']) && $order_request['shipping_method_id'] == "BOX_NOW_ID")
// Confirm that the 'box_now' parameter is available and not empty
if (isset($order_request['box_now']) && !empty($order_request['box_now'])) {
// Access and utilize locker data as needed
$locker_id = $order_request['box_now']['locker_id'];
$name = $order_request['box_now']['name'];
$address = $order_request['box_now']['address'];
$postcode = $order_request['box_now']['postcode'];
$latitude = $order_request['box_now']['lat'];
$longitude = $order_request['box_now']['lng'];
// Get order id
$order_id = $order['order_id'];
// Implement custom processing with locker data here
}
}
}
}
}