0
votes

I create Product slider plugin for woocommerce. in my plugin i need to display quantity with add to cart button in product slide view. following code i added woocommerce_quantity_input() function to display quantity field within the div. but unexpectly quantity field display out of the div. how to fix this issue

$displayslide.='<div class="productcartsection">';  

$displayslide.="<form action=".esc_url( $product->add_to_cart_url() )." class='cart' method='post' enctype='multipart/form-data'>"; 

$displayslide.=woocommerce_quantity_input();    

$displayslide.='<button type="submit" class="button alt">Add Cart</button>';

$displayslide.="</form>";    

$displayslide.='</div>';

enter image description here

enter image description here

1
check the html of the page and see if you can get the reason?Giacomo M
html code added. @GiacomoMGokulanathan

1 Answers

1
votes

The problem is that woocommerce_quantity_input echoes (output) the field by default. When you want to add it to a string and then output, you need to pass the third value of it as false. This is the function declaration on WC plugin:

function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) {

So you can change your code this way:

$displayslide .= woocommerce_quantity_input(array(), null, false);