dqaq59269 2012-07-31 18:07
浏览 32
已采纳

如何在一个页面上选择产品数量并将值传递给cart.php

Say on front page you have a promotional section that allowed you to increase/decrease the quanitity of products you want, then it calculates the price for you automatically. There's a button I added with an href of

 <?php echo get_home_url(); ?>/shop/?add-to-cart=9

Which adds a single product to your cart, and takes you to cart.php where you can increase or decrease quantity.

What can I do, or what direction can I take, to get the front-page quantity passed to the cart.php quantity?

For example, my front page code is like this:

http://jsfiddle.net/7BDwP/811/

  • 写回答

2条回答 默认 最新

  • douhui0975 2012-07-31 19:33
    关注

    The only support it has is: (via URL)

    ?add-to-cart=variation&product_id=1100
    

    So you need to make a hidden form element called Qty:

    <input name="quantity" data-min="1" data-max="0" value="1" size="4" title="Qty" class="input-text qty text" maxlength="12">
    

    But since you have more than one. You would do

    <form action="/shop/?add-to-cart=variation&amp;product_id=1100" class="variations_form cart" method="post" enctype="multipart/form-data">
    
    Size
    <select>
    <option value="">Choose an option…</option>
    <option value="large">Large</option>
    <option value="medium">Medium</option>
    <option value="small" selected="selected">Small</option>
    <option value="x-large">X-Large</option>
    </select>
    
    Colour
    <select id="pa_colour" name="attribute_pa_colour" style="opacity:0">
    <option value="">Choose an option…</option>
    <option value="black" selected="selected">Black</option>
    </select>
    
    <input type="hidden" name="variation_id" value="1104">
    
    <input name="quantity" data-min="1" data-max="0" value="1"
    size="4" title="Qty" class="input-text qty text" maxlength="12">
    
    <button type="submit" class="button alt">Add to cart</button>
    <input type="hidden" name="product_id" value="1100"></div>
    
    </form>
    

    Just make sure your Ids and Names are unique, make an jQuery Ajax field which updates that Qty value. You can only submit through the form method UNLESS you edit the core PHP values and allow REQUEST rather than GET.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法