• Resolved albertodominguezt

    (@albertodominguezt)


    Hi!

    I have modify the plugin so i can add them to the One Page Checkout plugin, but is not quite working.

    i modified the function….

    
    function wqb_assets() { echo "
      <style>
        div.product-quantity div{display:inline;white-space:nowrap}
        .product-quantity button.qty{padding:.3em 1em;user-select:none}
        button.qty{display:inline-block!important;font-weight:bold;outline:none;-webkit-transition:all .3s;transition:all .3s}
        button.qty:hover{box-shadow:-1px 0px #ccc;-webkit-filter:brightness(95%);filter:brightness(95%);transform:scale(1.05)}
        button.qty:active{transform:scale(1.15)}
        button.qty.minus{border-right:1px solid #ccc;-webkit-filter:brightness(95%);filter:brightness(95%)}
        button.button.update_cart{background:#080!important;color:#fff!important}
        button[name=add-to-cart],.single_add_to_cart_button{margin-top:.8em}
        @media (min-width:769px) {.product-quantity button.qty{max-width:1.85em!important}}
      </style>
      
      <script type='text/javascript'>
        function wqb_action(iteration,q) {
          var qty=[].slice.call(document.querySelectorAll('div.quantity'));
          if(!qty) return;
          for(i=0; i<qty.length; i++) if(i==iteration) {
            v=qty[i].childNodes[3];
            if(!v) return;
            if(v.value<=1 && q<1) return;
            v.value=parseInt(v.value)+parseInt(q);
          }
          
            
        (jQuery( 'body' ).trigger( 'update_checkout' );
       
    
        }
      </script>";
    }
    

    I remove this part, since i dont have a update_cart button

    
          if(document.getElementsByName('update_cart').length>0) {
            update_cart=document.getElementsByName('update_cart')[0];
            update_cart.disabled=false;
            update_cart.classList.add('update_cart');
          }
    

    The buttons appear and the change the quantity, but it does update the order, and it update it with:

    
        (jQuery( 'body' ).trigger( 'update_checkout' );
    

    This will refresh the previous value, without the increments on the quantity.

    Please help me out to fix it.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter albertodominguezt

    (@albertodominguezt)

    From my point of view, ( im not an expert on JS) this function is not updating the field correctly, or the update js function is not getting the new value.

        function wqb_action(iteration,q) {
          var qty=[].slice.call(document.querySelectorAll('div.quantity'));
          if(!qty) return;
          for(i=0; i<qty.length; i++) if(i==iteration) {
            v=qty[i].childNodes[3];
            if(!v) return;
            if(v.value<=1 && q<1) return;
            v.value=parseInt(v.value)+parseInt(q);
          }
    
    Plugin Author RLDD

    (@rermis)

    Hi Alberto,

    Thank you for reporting this issue, I found that One Page Checkout requires an onchange event to bubble to record the quantity change. Version 1.0.19 addresses the issue where the page does not refresh when using the WC plugin One Page Checkout. Please upgrade to 1.0.19, clear your cache, and let me know if the issue persists.

    Thank you!

    Thread Starter albertodominguezt

    (@albertodominguezt)

    Hello @rermis ! it did worked! Thanks

    but i had to change the hook action location so it would appear correctly….

    //add_action('woocommerce_after_cart','wqb_cart');
    add_action('woocommerce_review_order_after_cart_contents','wqb_cart');

    AND

    //add_action('woocommerce_after_add_to_cart_quantity','wqb_assets');
    add_action('woocommerce_review_order_after_cart_contents','wqb_assets');
    Plugin Author RLDD

    (@rermis)

    Hi Alberto,

    Thank you, I appreciate the details. So that I can fix this in future versions, can you tell me if there is an issue if the hooks that you added for woocommerce_review_order_after_cart_contents is called in addition to the existing hooks? I am wondering whether the new hook needs a conditional statement specifically if the one page checkout plugin is installed.

    Thread Starter albertodominguezt

    (@albertodominguezt)

    Here is the Original templeate (tbody only) of the review-order-opc.php

    
    <tbody>
    			<?php
    				do_action( 'woocommerce_review_order_before_cart_contents' );
    
    				foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    					$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
    
    					if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
    						?>
    						<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item opc_cart_item', $cart_item, $cart_item_key ) ); ?>" data-add_to_cart="<?php echo $_product->get_id(); ?>" data-update_key="<?php echo $cart_item_key; ?>">
    							<td class="product-name">
    								<div class="product-remove" >
    									<?php echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<a href="%s" class="remove" title="%s">&times;</a>', esc_url( wcopc_get_cart_remove_url( $cart_item_key ) ), __( 'Remove this item', 'wcopc' ) ), $cart_item_key ); ?>
    								</div>
    								<div class="product-details" >
    									<?php echo apply_filters( 'woocommerce_cart_item_name', wcopc_get_products_name( $_product ), $cart_item, $cart_item_key ); ?>
    									<?php echo wcopc_get_formatted_cart_item_data( $cart_item ); ?>
    								</div>
    								<div class="product-quantity">
    								<?php
    									if ( $_product->is_sold_individually() ) {
    										$product_quantity = sprintf( '1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key );
    									} else {
    										$product_quantity = woocommerce_quantity_input( array(
    											'input_name'  => "cart[{$cart_item_key}][qty]",
    											'input_value' => $cart_item['quantity'],
    											'max_value'   => $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(),
    											'min_value'   => '0'
    										), $_product, false );
    									}
    
    									echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item );
    								?>
    								</div>
    							</td>
    							<td class="product-total">
    								<?php echo apply_filters( 'woocommerce_cart_item_subtotal', WC()->cart->get_product_subtotal( $_product, $cart_item['quantity'] ), $cart_item, $cart_item_key ); ?>
    							</td>
    						</tr>
    						<?php
    					}
    				}
    
    				do_action( 'woocommerce_review_order_after_cart_contents' );
    			?>
    </tbody>
    

    I had to edit it and added:
    do_action( 'woocommerce_after_cart_item_quantity' );

    right after:
    echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item );

    so that the button appear in the desired position.

    Thread Starter albertodominguezt

    (@albertodominguezt)

    Hello again @rermis .

    For some reason the buttons show up but disappear right away.

    here is a link to a video a recorded.
    https://www.dropbox.com/s/dhk9g8zyt9wvtu7/Los%20Deditos%20De%20Mary%20-%20Google%20Chrome%202020-07-09%2016-29-19.mp4?dl=0

    Plugin Author RLDD

    (@rermis)

    Hi Alberto, was this taken using AutoCoupons version 1.0.21? Also, have you tried reversing the earlier edits to review-order-opc.php to see if the plugin works on it’s own? I would be happy to test this in more depth for you, but One Page Checkout is not a free plugin.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘quantity button on order review one page checkout’ is closed to new replies.