如何移动存档页面上的数量输入框? [英] How to move quantity input box on archive page?

查看:51
本文介绍了如何移动存档页面上的数量输入框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的 Woocommerce 网站中,我们使用

下面是content-product.php模板文件的代码:

is_visible() ) {返回;}?><li <?php wc_product_class();?>><?php/*** 钩子:woocommerce_before_shop_loop_item.** @hooked woocommerce_template_loop_product_link_open - 10*/do_action('woocommerce_before_shop_loop_item');/*** 钩子: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');/*** 钩子:woocommerce_shop_loop_item_title.** @hooked woocommerce_template_loop_product_title - 10*/do_action('woocommerce_shop_loop_item_title');/*** 钩子: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');/*** 钩子: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');?>

解决方案

使用此代码并删除已为存档页面显示的添加到购物车按钮,通过 css 不显示,然后添加此代码.

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);功能ace_shop_page_add_quantity_field() {全球 $product;?><form class="cart" action="" method="post" enctype='multipart/form-data'><?php woocommerce_quantity_input( 数组('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),'输入值' =>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 按钮 alt"><?php echo esc_html( $product->single_add_to_cart_text() );?></表单><?php}

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:

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>

解决方案

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
}

这篇关于如何移动存档页面上的数量输入框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆