1) In you cart template add button (should be inside of line items loop)
{% assign customlink = false %}
{% if item.properties and item.properties.configId %}
{% assign customlink = item.properties.productUrl | append: '?configid=' | append: item.properties.configId %}
{% endif %}
{% if item.properties and item.properties._configId %}
{% assign customlink = item.properties._productUrl | append: '?configid=' | append: item.properties._configId %}
{% endif %}
{% if customlink %}
<a class="cpb-modify-product--js" href="{{ customlink }}&modifyProduct={{ item.key }}">Modify product</a><br>
{% endif %}
2) Add to your "customproductbuilder-initializer.liquid" file jQuery and new script (check to not repeat if it's already there)
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
{{ 'customproductbuilder.js' | asset_url | script_tag }}
3) Create new asset "customproductbuilder.js"
4) Fill it with code:
;(function($) {
document.body.addEventListener('CPB_ON_PRODUCT_MOUNTED', init);
function init() {
modifyProductInCartInit();
}
function modifyProductInCartInit() {
if(window.location.search.indexOf('&modifyProduct=') === -1) return;
var keyId = window.location.search.split('&modifyProduct=')[1];
keyId = keyId.split('&')[0];
var addToCartBtn = $('.cpb-add-to-cart-button');
addToCartBtn.find('span').html('Update Cart');
addToCartBtn.on('click', function() {
$.get('/cart/change.js', {
'id': keyId,
'quantity': 0
});
});
}
})(jQuery);
You can remove or edit this line "addToCartBtn.find('span').html('Update Cart');" if you don't want to change the add to cart button text or want to change it other way.
Comments
0 comments
Please sign in to leave a comment.