-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #401 from bootscore/Update-WooCommerce-7.4-templates
Update WooCommerce 7.4 templates
- Loading branch information
Showing
5 changed files
with
101 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,82 @@ | ||
jQuery(function ($) { | ||
|
||
// Review Checkbox Products | ||
$('.comment-form-cookies-consent').addClass('form-check'); | ||
$('#wp-comment-cookies-consent').addClass('form-check-input'); | ||
$('.comment-form-cookies-consent label').addClass('form-check-label'); | ||
|
||
// Checkout Form Validation | ||
$('body').on('blur change', '.form-row input', function () { | ||
$('.woocommerce form .form-row.woocommerce-validated .select2-container, .woocommerce form .form-row.woocommerce-validated input.input-text, .woocommerce form .form-row.woocommerce-validated select, .woocommerce form .form-row.woocommerce-validated .form-check-input[type=checkbox]').removeClass('is-invalid').addClass('is-valid'); | ||
$('.woocommerce form .form-row.woocommerce-invalid .select2-container, .woocommerce form .form-row.woocommerce-invalid input.input-text, .woocommerce form .form-row.woocommerce-invalid select, .woocommerce form .form-row.woocommerce-invalid .form-check-input[type=checkbox]').removeClass('is-valid').addClass('is-invalid'); | ||
}); | ||
|
||
// Single-product Tabs | ||
// First item active | ||
$('.wc-tabs .nav-item:first-child a').addClass('active'); | ||
|
||
// Set active class to nav-link | ||
$('body').on('click', '.wc-tabs li a', function (e) { | ||
e.preventDefault(); | ||
var $tab = $(this); | ||
var $tabs_wrapper = $tab.closest('.wc-tabs-wrapper, .woocommerce-tabs'); | ||
var $tabs = $tabs_wrapper.find('.wc-tabs'); | ||
|
||
$tabs.find('li a').removeClass('active'); | ||
$tabs_wrapper.find('.wc-tab, .panel:not(.panel .panel)').hide(); | ||
|
||
$tab.closest('li a').addClass('active'); | ||
$tabs_wrapper.find($tab.attr('href')).show(); | ||
}); | ||
// Single-product Tabs End | ||
|
||
// WC Quantity Input | ||
if (!String.prototype.getDecimals) { | ||
String.prototype.getDecimals = function () { | ||
var num = this, | ||
match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); | ||
if (!match) { | ||
return 0; | ||
} | ||
return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0)); | ||
}; | ||
} | ||
// Quantity "plus" and "minus" buttons | ||
$(document.body).on('click', '.plus, .minus', function () { | ||
var $qty = $(this).closest('.quantity').find('.qty'), | ||
currentVal = parseFloat($qty.val()), | ||
max = parseFloat($qty.attr('max')), | ||
min = parseFloat($qty.attr('min')), | ||
step = $qty.attr('step'); | ||
|
||
// Format values | ||
if (!currentVal || currentVal === '' || currentVal === 'NaN') currentVal = 0; | ||
if (max === '' || max === 'NaN') max = ''; | ||
if (min === '' || min === 'NaN') min = 0; | ||
if (step === 'any' || step === '' || step === undefined || parseFloat(step) === 'NaN') step = 1; | ||
|
||
// Change the value | ||
if ($(this).is('.plus')) { | ||
if (max && currentVal >= max) { | ||
$qty.val(max); | ||
} else { | ||
$qty.val((currentVal + parseFloat(step)).toFixed(step.getDecimals())); | ||
} | ||
} else { | ||
if (min && currentVal <= min) { | ||
$qty.val(min); | ||
} else if (currentVal > 0) { | ||
$qty.val((currentVal - parseFloat(step)).toFixed(step.getDecimals())); | ||
} | ||
} | ||
|
||
// Trigger change event | ||
$qty.trigger('change'); | ||
}); | ||
// WC Quantity Input End | ||
|
||
jQuery(function ($) { | ||
|
||
// Review Checkbox Products | ||
$('.comment-form-cookies-consent').addClass('form-check'); | ||
$('#wp-comment-cookies-consent').addClass('form-check-input'); | ||
$('.comment-form-cookies-consent label').addClass('form-check-label'); | ||
|
||
// Checkout Form Validation | ||
$('body').on('blur change', '.form-row input', function () { | ||
$('.woocommerce form .form-row.woocommerce-validated .select2-container, .woocommerce form .form-row.woocommerce-validated input.input-text, .woocommerce form .form-row.woocommerce-validated select, .woocommerce form .form-row.woocommerce-validated .form-check-input[type=checkbox]').removeClass('is-invalid').addClass('is-valid'); | ||
$('.woocommerce form .form-row.woocommerce-invalid .select2-container, .woocommerce form .form-row.woocommerce-invalid input.input-text, .woocommerce form .form-row.woocommerce-invalid select, .woocommerce form .form-row.woocommerce-invalid .form-check-input[type=checkbox]').removeClass('is-valid').addClass('is-invalid'); | ||
}); | ||
|
||
// Single-product Tabs | ||
// First item active | ||
$('.wc-tabs .nav-item:first-child a').addClass('active'); | ||
|
||
// Set active class to nav-link | ||
$('body').on('click', '.wc-tabs li a', function (e) { | ||
e.preventDefault(); | ||
var $tab = $(this); | ||
var $tabs_wrapper = $tab.closest('.wc-tabs-wrapper, .woocommerce-tabs'); | ||
var $tabs = $tabs_wrapper.find('.wc-tabs'); | ||
|
||
$tabs.find('li a').removeClass('active'); | ||
$tabs_wrapper.find('.wc-tab, .panel:not(.panel .panel)').hide(); | ||
|
||
$tab.closest('li a').addClass('active'); | ||
$tabs_wrapper.find($tab.attr('href')).show(); | ||
}); | ||
// Single-product Tabs End | ||
|
||
// WC Quantity Input | ||
if (!String.prototype.getDecimals) { | ||
String.prototype.getDecimals = function () { | ||
var num = this, | ||
match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); | ||
if (!match) { | ||
return 0; | ||
} | ||
return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0)); | ||
}; | ||
} | ||
// Quantity "plus" and "minus" buttons | ||
$(document.body).on('click', '.plus, .minus', function () { | ||
var $qty = $(this).closest('.quantity').find('.qty'), | ||
currentVal = parseFloat($qty.val()), | ||
max = parseFloat($qty.attr('max')), | ||
min = parseFloat($qty.attr('min')), | ||
step = $qty.attr('step'); | ||
|
||
// Format values | ||
if (!currentVal || currentVal === '' || currentVal === 'NaN') currentVal = 0; | ||
if (max === '' || max === 'NaN') max = ''; | ||
if (min === '' || min === 'NaN') min = 0; | ||
if (step === 'any' || step === '' || step === undefined || parseFloat(step) === 'NaN') step = 1; | ||
|
||
// Change the value | ||
if ($(this).is('.plus')) { | ||
if (max && currentVal >= max) { | ||
$qty.val(max); | ||
} else { | ||
$qty.val((currentVal + parseFloat(step)).toFixed(step.getDecimals())); | ||
} | ||
} else { | ||
if (min && currentVal <= min) { | ||
$qty.val(min); | ||
} else if (currentVal > 0) { | ||
$qty.val((currentVal - parseFloat(step)).toFixed(step.getDecimals())); | ||
} | ||
} | ||
|
||
// Trigger change event | ||
$qty.trigger('change'); | ||
}); | ||
|
||
// Make quantity input visible in product page if only 1 product is in stock | ||
// WooCommerce 7.4.0 https://github.com/woocommerce/woocommerce/blob/2bf9f577952d7a225365fe7728b3187b5be7b701/plugins/woocommerce/templates/global/quantity-input.php | ||
$('.quantity [max="1"]').attr('type', 'number'); | ||
// WC Quantity Input End | ||
|
||
}); // jQuery End |