![](/img/trans.png)
[英]WooCommerce custom cart item price on add-to cart via the URL
[英]shopp plugin add existing cart item with custom price
我有一個標價為29 $的普通產品,我想要的是在此產品上額外收取10 $的價格,再給另一個商品(相同產品),意味着以29 $購買一個,以39 $購買兩個。
為此,我使用此代碼將產品添加到購物車
<?php
if($_POST['duplica_las_flores'] != '' && isset($_POST['duplica_las_flores']))
{
$customProdcutId = $_POST['productID'];
if(is_numeric($customProdcutId))
{
global $Shopp; //load up our $Shopp variable
$Product = new Product(absint($customProdcutId)); //We have to create a Product object to use in our add to cart function.
if(!empty($Product->id)){
$pricing = 10.00;
$result = $Shopp->Order->Cart->add(1, $Product, $pricing, false, array(), array()); //This is where "the magic happens"
}
}
?>
在此情況下,如果在單個產品頁面中選中了復選框,則將添加具有我的自定義價格(10 $)的另一個產品,但這將添加具有相同價格(29 $)的新產品。
如何在這里更改第二個產品的價格,或者還有其他方法可以這樣做?
謝謝
比修改購物車代碼更容易,它是使用內置的附加組件系統,並創建一個用於添加其他物品的附加組件。
優點:節省一些時間在插件代碼中弄亂
缺點:如果要處理實物產品,則不會更新庫存
我找不到它的文檔,但此處提到了“附加組件”: https : //shopplugin.net/docs/the-catalog/product-settings/
如果您沒有太多不同的產品采用這種定價方式,則可以查看折扣 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.