ds15812330851 2018-04-23 09:12
浏览 24
已采纳

WP WooCommerce页面产品数量

I create single page for product. Hopw I can add quantity option before button "add to card"?

enter image description here

    <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-->

I try with form code, and it working. But I want to find another way and add to first code. This is code for form.

<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>
  • 写回答

1条回答 默认 最新

  • dousuiben8395 2018-04-23 09:24
    关注

    Please try to this WooCommerce function

    woocommerce_quantity_input();
    

    OR If you want to show both the Qty textbox and addtocart button, there is an another WooCommerce function.Check as below.

    do_action('woocommerce_simple_add_to_cart');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来