简体   繁体   English

woocommerce_quantity_input在添加到购物车循环中不起作用

[英]woocommerce_quantity_input doesn't work in add to cart loop

I need a quantity selection block in the add to cart loop on the product list page in woocommerce. 在woocommerce的产品列表页面上的添加到购物车循环中,我需要一个数量选择块。 Woocommerce codex has a page which allows me to do it by basically putting this block of code instead of the existing one: Woocommerce Codex有一个页面,使我可以通过基本上放置此代码块而不是现有代码块来执行此操作:

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

        <?php woocommerce_quantity_input(); ?>

        <button type="submit" class="button alt"><?php echo $label; ?></button>

    </form>

However, that form doesn't add to my current AJAX setup and other nice tricks that come with my original add to cart button. 但是,该表单不会添加到我当前的AJAX设置中,也不会添加到我原来的“添加到购物车”按钮中的其他不错的技巧。 This is the original code of the add to cart button, which works like i want it, except for missing the quantity input: 这是“添加到购物车”按钮的原始代码,其工作方式与我想要的一样,只是缺少输入的数量:

<?php
/**
 * Loop Add to Cart
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.1.0
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

global $product, $jckqv;

$jckqv->displayBtn($product->id); 

echo '<div class="product-buttons">';

echo apply_filters( 'woocommerce_loop_add_to_cart_link',
    sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>',
        esc_url( $product->add_to_cart_url() ),
        esc_attr( $product->id ),
        esc_attr( $product->get_sku() ),
        $product->is_purchasable() ? 'add_to_cart_button' : '',
        esc_attr( $product->product_type ),
        esc_html( $product->add_to_cart_text() )
    ),
$product );

echo do_shortcode('[yith_compare_button]');
echo do_shortcode('[yith_wcwl_add_to_wishlist]');



echo '</div>';

I need to somehow put the woocommerce_quantity_input in this code, to retain the current functionality, but to add the quantity input. 我需要以某种方式将woocommerce_quantity_input放入此代码中,以保留当前功能,但要添加数量输入。 I tried to do it in many various ways, but unfortunately my PHP skills lack. 我试图以多种方式做到这一点,但是不幸的是我的PHP技能缺乏。 Please help. 请帮忙。 Thank you 谢谢

For anybody who might still need to use this 对于可能仍需要使用此功能的任何人

  <?php woocommerce_quantity_input(); ?> 

You need to echo it. 您需要回显它。 As easy as that 那样简单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WooCommerce Ajax 添加到购物车数量不起作用 - WooCommerce Ajax add to cart quantity doesn't work woocommerce_quantity_input() 在商店页面 woocommerce 上不起作用 - woocommerce_quantity_input() not working on shop page woocommerce 在“woocommerce_quantity_input”可插拔函数中获取产品ID - Get product id in “woocommerce_quantity_input” pluggable function 为什么 woocommerce_loop_add_to_cart_link 在 WooCommerce 块中不起作用? - Why woocommerce_loop_add_to_cart_link doesn't work within WooCommerce blocks? 设置最小输入量,甚至在Woocommerce中添加到购物车的ajax上 - Set minimum input quantity even on ajax add to cart in Woocommerce 用 WooCommerce 中的自定义数量输入字段替换“添加到购物车” - Replace “add to cart” with custom quantity input fields in WooCommerce WooCommerce商店页面:添加到购物车按钮上的数量输入 - WooCommerce Shop page: Quantity input on add to cart button 如何在 woocommerce 中的购物车数量旁边添加文本 - How to add text next to the quantity on the cart in woocommerce 将数量选择添加到 woocommerce 购物车小部件 - add quantity select to woocommerce shopping cart widget 自定义数量字段在 Woocommerce 存档页面上不起作用 - Custom quantity field doesn't work on Woocommerce archive pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM