[英]How to make add to cart button on custom page (not shop/product page) Woocommerce
i made new page on my site that people choose PC part to buy..我在我的网站上创建了一个新页面,人们选择购买 PC 部件。
My case is how to create a button for add all product choosen to cart then redirect to the cart pages.我的情况是如何创建一个按钮,将所有选择的产品添加到购物车,然后重定向到购物车页面。
Select list HTML Code选择列表 HTML 代码
<div><select id="ddrakit-processor" class="ddrakit"><option value='{"gaming":"0","render":"0","priceperform":"0"}'>- Pilih processor -</option><option value='{"product_id":9,"category_id":17,"harga":"100000000","gaming":"20","render":"10","priceperform":"20"}'>Intel i99 - Rp. 100,000,000,-</option></select></div>
<div><select id="ddrakit-motheboard" class="ddrakit"><option value='{"gaming":"0","render":"0","priceperform":"0"}'>- Pilih motherboard -</option><option value='{"product_id":11,"category_id":20,"harga":"80000","gaming":"40","render":"50","priceperform":"10"}'>ASUS ROG Z999 - Rp. 80,000,-</option></select></div>
<div><select id="ddrakit-ram" class="ddrakit"><option value='{"gaming":"0","render":"0","priceperform":"0"}'>- Pilih memory RAM -</option><option value='{"product_id":10,"category_id":19,"harga":"500000","gaming":"40","render":"10","priceperform":"20"}'>V-GEN 128GB DDR8 - Rp. 500,000,-</option></select></div>
<div><select id="ddrakit-vga" class="ddrakit"><option value='{"gaming":"0","render":"0","priceperform":"0"}'>- Pilih graphic card -</option><option value='{"product_id":8,"category_id":16,"harga":"2000000","gaming":"10","render":"20","priceperform":"10"}'>RADEON RX 999 - Rp. 2,000,000,-</option><option value='{"product_id":16,"category_id":16,"harga":"16499000","gaming":"20","render":"10","priceperform":"20"}'>MSI - GeForce GTX 1080 Ti Gaming X Trio - Rp. 16,499,000,-</option></select></div>
<div><select id="ddrakit-psu" class="ddrakit"><option value='{"gaming":"0","render":"0","priceperform":"0"}'>- Pilih power supply -</option><option value='{"product_id":17,"category_id":22,"harga":"50000","gaming":"10","render":"50","priceperform":"10"}'>Corsair RM8000 8000w - Rp. 50,000,-</option></select></div>
<div><select id="ddrakit-casing" class="ddrakit"><option value='{"gaming":"0","render":"0","priceperform":"0"}'>- Pilih Casing -</option><option value='{"product_id":12,"category_id":21,"harga":"5020000","gaming":"10","render":"10","priceperform":"10"}'>Corsair Casing Gaming - Rp. 5,020,000,-</option></select></div>
Thank you.谢谢你。
在您的自定义页面中使用此链接
<a href="?add-to-cart=<?php echo $loop->post->ID; ?>" rel="nofollow" data-product-id="<?php echo $loop->post->ID; ?>" class="btn btn-primary">Add to cart</a>
Are you saying a form?你说的是表格? I'd use a backend server to handle the form and do the redirect to the checkout page and whatnot.
我会使用后端服务器来处理表单并重定向到结帐页面等等。 Submitting form is what you should use and it's straightforward to implement.
提交表单是您应该使用的,并且实施起来很简单。
you may paste this where you want to show add to cart button您可以将此粘贴到要显示添加到购物车按钮的位置
<?php
global $product;
$pid = $product->get_id();
?>
<a href="<?php echo do_shortcode( '[add_to_cart_url id=' . $pid . ']' ) ?>" class="your-classes-here">Add to cart</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.