如何在自定义页面(而不是商店/产品页面)上添加到购物车按钮Woocommerce

时间:2018-04-26 12:41:54

标签: javascript php jquery wordpress woocommerce

我在我的网站上制作了新页面,人们选择PC部件购买..

我的情况是如何创建一个按钮,用于将所有产品添加到购物车,然后重定向到购物车页面。

enter image description here

选择列表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>

谢谢。

3 个答案:

答案 0 :(得分:1)

在自定义页面中使用此链接

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

答案 1 :(得分:0)

你在说一张表格吗?我将使用后端服务器来处理表单并重定向到结帐页面等等。提交表单是您应该使用的,并且它很容易实现。

答案 2 :(得分:0)

您可以将其粘贴到要显示的位置添加到购物车按钮

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