Skip to content

Instantly share code, notes, and snippets.

@duonghoangdung
Last active October 30, 2019 08:38
Show Gist options
  • Save duonghoangdung/493aebad31f78cf9a55bf56620506bf7 to your computer and use it in GitHub Desktop.
Save duonghoangdung/493aebad31f78cf9a55bf56620506bf7 to your computer and use it in GitHub Desktop.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
(function($) {
"use strict";
if(!$('input[id^="attribute_productlist_"]:checked').prop('required')) {
$('input[id^="attribute_productlist_"]').val('0');
$('form[data-cart-item-add]').on('submit', function(e){
e.preventDefault();
var productPickedId = $('input[id^="attribute_productlist_"]:checked').data('product-id');
setTimeout(function() {$.ajax('/cart.php?action=add&product_id=' + productPickedId)}, 1000);
});
}
})(window.jQuerySupermarket || window.jQuery || jQuery);
</script>
  1. Add Script to Footer scripts
    1.1 Open the Footer scripts editor: Store Manager ==> Store front ==> Footer scripts
    1.2 Add script above to footer editor and save.
    1.3 Edit footer links content.

    • To edit footer link content. In footer link custom js you find: java const links = [{}] and edit text and link. Do not alter the structure.
  2. Add code in the product-list.html
    2.1 Open theme editor: Store Manager ==> Store front ==> Current Theme ==> Advanced ==> Edit Theme Files.
    2.2 In here you browser follow the path bellow: templates -> components -> products -> options -> product-list.html

    • Open product-list.html file and insert code behind param id="attribute_productlist_0_{{id}}" in line:37 insert this code: javadata-product-id="{{data}}"
      The code look like:
    value="0"
    id="attribute_productlist_0_{{id}}"
    data-product-id="{{data}}" // this is the code inserted
    checked="{{#if defaultValue '==' 0}}checked{{/if}}" required>
    • Chooes Save & apply file.
  3. Open any product detail have product pick list and check it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment