Skip to content

Commit

Permalink
Merge pull request #401 from bootscore/Update-WooCommerce-7.4-templates
Browse files Browse the repository at this point in the history
Update WooCommerce 7.4 templates
  • Loading branch information
crftwrk committed Feb 16, 2023
2 parents 8631421 + eccb9af commit abe5cc4
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 95 deletions.
5 changes: 5 additions & 0 deletions scss/bootscore_woocommerce/_wc_qty_btn.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ WooCommerce Quantity Input
@extend :disabled;
}
}

// Hide quantity input if product is sold individually
.sold-individually .quantity {
display: none;
}
8 changes: 4 additions & 4 deletions woocommerce/ajax-cart/ajax-add-to-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function bootscore_product_page_ajax_add_to_cart_js() {

});

$('a.ajax_add_to_cart:not(.outofstock a.ajax_add_to_cart)').on('click', function(e) {
$('a.ajax_add_to_cart').on('click', function(e) {

e.preventDefault();

Expand Down Expand Up @@ -136,9 +136,9 @@ function bootscore_product_page_ajax_add_to_cart_js() {

let notice = '';
if (response.error == true) {
notice = `<div class='woocommerce-message alert alert-danger'><?php _e('You cannot add another', 'bootscore'); ?>${prod_title}<?php _e('to your cart.', 'bootscore'); ?></div>`;
notice = `<div class='woocommerce-error'><?php _e('You cannot add another', 'bootscore'); ?>${prod_title}<?php _e('to your cart.', 'bootscore'); ?></div>`;
} else {
notice = `<div class="woocommerce-message alert alert-success">“${prod_title}<?php _e('has been added to your cart.', 'bootscore'); ?></div>`;
notice = `<div class="woocommerce-message">“${prod_title}<?php _e('has been added to your cart.', 'bootscore'); ?></div>`;
}

// Add new notices to offcanvas
Expand All @@ -164,7 +164,7 @@ function bootscore_product_page_ajax_add_to_cart_js() {

// Hide alert in offcanvas-cart when offcanvas is closed
$('#offcanvas-cart').on('hidden.bs.offcanvas', function() {
$('#offcanvas-cart .woocommerce-message').remove();
$('#offcanvas-cart .woocommerce-message, #offcanvas-cart .woocommerce-error').remove();
});

// Refresh ajax mini-cart on browser back button
Expand Down
5 changes: 3 additions & 2 deletions woocommerce/cart/cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 7.0.1
* @version 7.4.0
*/

defined('ABSPATH') || exit;
Expand Down Expand Up @@ -143,7 +143,8 @@
<div class="coupon">
<div class="input-group">
<input type="text" name="coupon_code" class="form-control" id="coupon_code" value="" placeholder="<?php esc_attr_e('Coupon code', 'woocommerce'); ?>" />
<button type="submit" class="input-group-text btn btn-outline-primary<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?></button>
<label for="coupon_code" class="screen-reader-text"><?php esc_html_e( 'Coupon:', 'woocommerce' ); ?></label>
<button type="submit" class="input-group-text btn btn-outline-primary<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?>" name="apply_coupon" value="<?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?>"><?php esc_attr_e( 'Apply coupon', 'woocommerce' ); ?></button>
<?php do_action('woocommerce_cart_coupon'); ?>
</div>
</div>
Expand Down
20 changes: 8 additions & 12 deletions woocommerce/global/quantity-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 7.2.1
* @version 7.4.0
*
* @var bool $readonly If the input should be set to readonly mode.
* @var string $type The input type attribute.
*/

defined( 'ABSPATH' ) || exit;

/* translators: %s: Quantity. */
$label = ! empty( $args['product_name'] ) ? sprintf( esc_html__( '%s quantity', 'woocommerce' ), wp_strip_all_tags( $args['product_name'] ) ) : esc_html__( 'Quantity', 'woocommerce' );

// In some cases we wish to display the quantity but not allow for it to be changed.
if ( $max_value && $min_value === $max_value ) {
$is_readonly = true;
$input_value = $min_value;
} else {
$is_readonly = false;
}
?>
<div class="quantity input-group">
<?php
Expand All @@ -39,9 +35,9 @@
?>
<button type="button" class="input-group-text qty_button minus">-</button>
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_attr( $label ); ?></label>
<input
type="<?php echo $is_readonly ? 'text' : 'number'; ?>"
<?php echo $is_readonly ? 'readonly="readonly"' : ''; ?>
<input
type="<?php echo esc_attr( $type ); ?>"
<?php echo $readonly ? 'readonly="readonly"' : ''; ?>
id="<?php echo esc_attr( $input_id ); ?>"
class="input-text qty text form-control <?php echo esc_attr( join( ' ', (array) $classes ) ); ?>"
name="<?php echo esc_attr( $input_name ); ?>"
Expand All @@ -50,7 +46,7 @@ class="input-text qty text form-control <?php echo esc_attr( join( ' ', (array)
size="4"
min="<?php echo esc_attr( $min_value ); ?>"
max="<?php echo esc_attr( 0 < $max_value ? $max_value : '' ); ?>"
<?php if ( ! $is_readonly ): ?>
<?php if ( ! $readonly ): ?>
step="<?php echo esc_attr( $step ); ?>"
placeholder="<?php echo esc_attr( $placeholder ); ?>"
inputmode="<?php echo esc_attr( $inputmode ); ?>"
Expand Down
158 changes: 81 additions & 77 deletions woocommerce/js/woocommerce.js
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

0 comments on commit abe5cc4

Please sign in to comment.