Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // -------------
- // 1. Show Buttons
- add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_display_quantity_plus' , 15);
- function bbloomer_display_quantity_plus() {
- echo '<div class="qu-warp"><span class="quantitytext">'._x('Quantity', 'woocommerce').'</span> <button type="button" class="plus" >+<span class="screen-reader-text">'.__('plus 1 item', 'woocommerce').'</span></button>';
- }
- add_action( 'woocommerce_after_add_to_cart_quantity', 'bbloomer_display_quantity_minus' , 15);
- function bbloomer_display_quantity_minus() {
- echo '<button type="button" class="minus" >-<span class="screen-reader-text">'.__('minus 1 item', 'woocommerce').'</span></button></div>';
- }
- // Note: to place minus @ left and plus @ right replace above add_actions with:
- // add_action( 'woocommerce_before_add_to_cart_quantity', 'bbloomer_display_quantity_minus' );
- // add_action( 'woocommerce_after_add_to_cart_quantity', 'bbloomer_display_quantity_plus' );
- // -------------
- // 2. Trigger jQuery script
- add_action( 'wp_footer', 'bbloomer_add_cart_quantity_plus_minus' );
- function bbloomer_add_cart_quantity_plus_minus() {
- // Only run this on the single product page
- if ( ! is_product() ) return;
- ?>
- <script type="text/javascript">
- jQuery(document).ready(function($){
- $('form.cart').on( 'click', 'button.plus, button.minus', function() {
- // Get current quantity values
- var qty = $( this ).closest( 'form.cart' ).find( '.qty' );
- var val = parseFloat(qty.val());
- var max = parseFloat(qty.attr( 'max' ));
- var min = parseFloat(qty.attr( 'min' ));
- var step = parseFloat(qty.attr( 'step' ));
- // Change the value if plus or minus
- if ( $( this ).is( '.plus' ) ) {
- if ( max && ( max <= val ) ) {
- qty.val( max );
- } else {
- qty.val( val + step );
- }
- } else {
- if ( min && ( min >= val ) ) {
- qty.val( min );
- } else if ( val > 1 ) {
- qty.val( val - step );
- }
- }
- });
- });
- </script>
- <?php
- }
- remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );
- add_action( 'woocommerce_before_single_product', 'wc_print_notices', 60 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement