【问题标题】:WP WooCommerce page product quantityWP WooCommerce 页面产品数量
【发布时间】:2018-04-23 09:12:58
【问题描述】:

我为产品创建单页。如何在“添加到卡”按钮之前添加数量选项?

    <ul class="products-list">
    <?php
        $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => 'product-category', 'orderby' => 'rand' );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>

                <li class="product">    
                    <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
                        <?php woocommerce_show_product_sale_flash( $post, $product ); ?>
                        <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?></a>
                        <h3><?php the_title(); ?></h3>
                        <span class="price"><?php echo $product->get_price_html(); ?></span>   
                        <p class="shortdescription"><?php echo $product->get_short_description();?></p>

//QUNATITY

                    <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
                </li>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
</ul><!--/.products-->

我尝试使用表单代码,它工作正常。但我想找到另一种方法并添加到第一个代码中。这是表单的代码。

<form class="cart" action="http://localhost/product/safelogic-basic/" method="post" enctype="multipart/form-data">
<div class="quantity buttons_added clearfix">
    <div class="quantity_controll_con">
        <input type="button" class="quantity_controll minus" value="-">
        <input type="number" step="1" min="1" max="" name="quantity" value="1" title="Qty" class="input-text qty text" size="4" pattern="[0-9]*"
            inputmode="numeric">
        <input type="button" class="quantity_controll plus" value="+">
    </div>
</div>

<button type="submit" name="add-to-cart" value="6995" class="single_add_to_cart_button button alt">Add to cart</button>

</form>

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    请试试这个 WooCommerce 功能

    woocommerce_quantity_input();
    

    或者如果您想同时显示数量文本框和添加到购物车按钮,还有另一个 WooCommerce 功能。检查如下。

    do_action('woocommerce_simple_add_to_cart');
    

    【讨论】:

    • 谢谢,我将woocomerce_template_loop_add_to_card 替换为woocommerce_simple_add_to_cart,它正在工作
    • 乐于助人.. :)
    猜你喜欢
    • 1970-01-01
    • 2017-06-14
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多