The actual method to add items to the cart/checkout workflow varies by platform. This guide will show you where to locate the Klevu Add-To-Cart function if you should need to make adjustments, or write your own functionality.
General Use
The Klevu Add-To-Cart button calls the function klevu_addtocart
/*
* id : product ID
* url : product page URL
* qty : desired quantity (default 1)
*/
function klevu_addtocart( id, url, qty ) {
// Add-To-Cart logic here
}
Example
Simply implement the function klevu_addtocart with your own logic of what you would like to happen when a customer clicks on Add-To-Cart.
Enabling the button and/or changing the button text can be done using variables as presented below.
JS
|
<script type="text/javascript">
klevu_addToCartEnabled =true;// or false to disable
klevu_uc_userOptions ={addToCartButton:'Add To Bag!'// Custom button text}functionklevu_addtocart(id, url, qty){// Add your logic here!}</script>
Klevu Recommendations
The Klevu Recommendations Add-To-Cart function call contains an extra argument recsKey to identify the specific recommendations banner from where the click originated.
JS
|
<script type="text/javascript">functionklevu_addtocart(id, url, qty, recsKey){if( recsKey =='abc-123-xyz-321'){// Add a specific recommendation logic here!}else{// Add your logic here!}}</script>
Supported Klevu Apps / Extensions
If you are already using Klevu Search via a Klevu App/Extension, you may find that the Add-To-Cart button within the Klevu Templates or Recommendations is already set and operational.
There should be no need to further modify these functions. They are included below for reference.
Shopify
Configure in KMC : Smart Search → Customizations → Add To Cart
If modifications are required, it is strongly recommended to properly extend the Klevu module to avoid potential conflicts during future updates to the system.
SalesForce Commerce Cloud
Configure in KMC : Smart Search → Customizations → Add To Cart