Get started
Customization
Troubleshooting
Data sent to nShift when retrieving shipping methods
When using nShift Checkout (both via the nShift Checkout widget and via WooCommerce shipping) a request to retrieve available shipping methods will happen in checkout everytime the cart or the customer address changes. This is done via the GET delivery checkout request.
By default the following data is sent to nShift in this request:
- currency (currency for the order)
- language (language used for the order, fetched from
get_locale()
). - tocountry (customer country)
- tozipcode (customer post code)
- cartprice
- weight (sum of all cart items)
- Cart product shipping classes – the name of each shipping class with the following structure:
shipping_class_name=true
. - Coupons – the name of each coupon code with this structure:
coupon code name=true
. If the coupon code enables free shipping,free_shipping=true
will also be sent.
This data can be used when creating conditional logic in your nShift account.
Modify the data sent to nShift
If you want to add custom data to the request it is possible by using the filter ksc_delivery_checkouts_query_param
in the following way:
/**
* Add customer city to request.
**/
add_filter('ksc_delivery_checkouts_query_param', 'krokedil_ksc_delivery_checkouts_query_param');
function krokedil_ksc_delivery_checkouts_query_param( $args ) {
// Add customer city to request.
$args['tocity'] = WC()->customer->get_shipping_city();
return $args;
}
/**
* Add custom meta data from the products in cart.
**/
add_filter('ksc_delivery_checkouts_query_param', 'krokedil_ksc_delivery_checkouts_query_param');
function krokedil_ksc_delivery_checkouts_query_param( $args ) {
// Ensure we have a cart.
if ( ! WC()->cart ) {
return $args;
}
// Check all cart items.
foreach ( WC()->cart->get_cart() as $cart_item ) {
// Get the product from the cart item.
$product_id = ! empty( $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id'];
$product = wc_get_product( $product_id );
// If we don't have a product, continue.
if ( ! $product ) {
continue;
}
if( 'yes' === $product->get_meta('fits_in_box' ) ) {
$args['fits_in_box'] = 'true';
}
if( 'yes' === $product->get_meta('only_pallet') ) {
$args['only_pallet'] = 'true';
}
}
return $args;
}
How and where to insert the code?
To get the functions exemplified in this section to work you need to add the code to your WordPress project. You can add it as its own plugin, through the Code Snippets plugin, your theme’s functions.php file or something similar of your choice.