0
votes

In our Woocommerce website, we are using the Quantity Field on Shop Page for WooCommerce plugin. However, we don't like the position of the quantity box and want to move it so that it is directly below the "add to basket" button on our products.

This is the display that I get:

enter image description here

Below is the code of content-product.php template file:

<?php
/**
 * The template for displaying product content within loops
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/content-product.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce/Templates
 * @version 3.4.0
 */
defined( 'ABSPATH' ) || exit;
global $product;
// Ensure visibility.
if ( empty( $product ) || ! $product->is_visible() ) {
return;
}
?>
<li <?php wc_product_class(); ?>>
<?php
/**
 * Hook: woocommerce_before_shop_loop_item.
 *
 * @hooked woocommerce_template_loop_product_link_open - 10
 */
do_action( 'woocommerce_before_shop_loop_item' );
/**
 * Hook: woocommerce_before_shop_loop_item_title.
 *
 * @hooked woocommerce_show_product_loop_sale_flash - 10
 * @hooked woocommerce_template_loop_product_thumbnail - 10
 */
do_action( 'woocommerce_before_shop_loop_item_title' );
/**
 * Hook: woocommerce_shop_loop_item_title.
 *
 * @hooked woocommerce_template_loop_product_title - 10
 */
do_action( 'woocommerce_shop_loop_item_title' );
/**
 * Hook: woocommerce_after_shop_loop_item_title.
 *
 * @hooked woocommerce_template_loop_rating - 5
 * @hooked woocommerce_template_loop_price - 10
 */
do_action( 'woocommerce_after_shop_loop_item_title' );
/**
 * Hook: woocommerce_after_shop_loop_item.
 *
 * @hooked woocommerce_template_loop_product_link_close - 5
 * @hooked woocommerce_template_loop_add_to_cart - 10
 */
do_action( 'woocommerce_after_shop_loop_item' );
?>
</li>
2
Can't answer the question without any HTML and CSS code...Danoctum
@LoicTheAztec The only thing we have tried is reorganizing the code in the functions.php to try and get the quantity box to appear next to the add to basket button. We are running "WordPress 4.9.6 running X – Child Theme."user10057926
@LoicTheAztec I have edited my post and added the code inside simple.phpuser10057926
@LoicTheAztec Okay I will edit my post and post the content-product.php. Could you tell me how to move the quantity box so that it is directly beneath the add to basket button please.user10057926
Finally as this is made by a plugin, I really don't know which hook and priority is used by this plugin and if it's possible to do it (I suppose that the plugin is using woocommerce_template_loop_add_to_cart hook with some unknown priority). You should better ask the plugin support pages, if it's possible to make the changes you want and how. When using a plugin, you always get the limitations of this plugin. Also your theme seems making customizations on this, so this is getting more complicated…LoicTheAztec

2 Answers

0
votes

See the reference link for the positions

Add the code in functions.php file

/** woocommerce: change position of add-to-cart on single product **/
remove_action( 'woocommerce_single_product_summary', 
               'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 
            'woocommerce_template_single_add_to_cart', 5 );

OR

You can try with CSS

0
votes

use this code and remove add to cart button that is already showing for archive page, do it display none by css and then add this code.

remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 50 );

add_action( 'woocommerce_after_shop_loop_item', 'ace_shop_page_add_quantity_field', 99 );

function ace_shop_page_add_quantity_field() {
global $product;?>
<form class="cart" action="" method="post" enctype='multipart/form-data'>
<?php woocommerce_quantity_input( array(
'min_value'   => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
'max_value'   => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(),
) );
?>
<button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt">
<?php echo esc_html( $product->single_add_to_cart_text() );?>
</button>
</form>
<?php
}