Woocommerce最小/最大數量擴展和捆綁項目擴展之間存在衝突。我已經向Woo支持發表過演講,他們說無法關閉屬於捆綁項目的個別項目的最小/最大驗證。Woocommerce:將捆綁產品添加到購物車時關閉最小/最大驗證
當包含具有最小/最大限制的物品的購物車中添加了捆綁物品時,它會拋出購物者需要添加更多單個物品的錯誤。
我試圖關閉個別項目的最小/最大值驗證,當它們是添加到購物車的捆綁項目的一部分時。
重要注意事項:我需要仍然跟蹤各個項目的庫存。
我意識到編輯插件的危險性,因爲更新會在更新時丟失,但我願意冒這個風險才能使其發揮作用。 (我知道你可以製作插件的副本,這可能是我所做的。)
具體來說,我一直在嘗試修改爲複合項目製作的兼容性補丁,並使其適用於捆綁項目。
我發現這在他們的changelog:
2015-11-03 - version 2.3.9
* Fix - Variation level category exclude option not working.
* New - Compatibility with Composite Products plugin to disable min/max logic when product is of type composite.
並在插件四個地方找到參考複合物品的兼容性。下面是一個有檢查的複合產品和代碼,我加入到模仿它的代碼的函數的例子(相關代碼有**的爲重點)
public function check_rules($product, $quantity, $minimum_quantity, $maximum_quantity, $group_of_quantity) {
//**************************
// composite products plugin compatibility
if ($this->addons->is_composite_product($product->id)) {
return;
}
//**************************
//**************************
//This is what I added:
// bundled products plugin compat
if ($this->addons->wc_pb_is_bundled_cart_item($product->id)) {
return;
}
//**************************
if ($minimum_quantity > 0 && $quantity < $minimum_quantity) {
$this->add_error(sprintf(__('The minimum allowed quantity for %s is %s - please increase the quantity in your cart.', 'woocommerce-min-max-quantities'), $product->get_title(), $minimum_quantity));
} elseif ($maximum_quantity > 0 && $quantity > $maximum_quantity) {
$this->add_error(sprintf(__('The maximum allowed quantity for %s is %s - please decrease the quantity in your cart.', 'woocommerce-min-max-quantities'), $product->get_title(), $maximum_quantity));
}
if ($group_of_quantity > 0 && ($quantity % $group_of_quantity)) {
$this->add_error(sprintf(__('%s must be bought in groups of %d. Please add or decrease another %d to continue.', 'woocommerce-min-max-quantities'), $product->get_title(), $group_of_quantity, $group_of_quantity - ($quantity % $group_of_quantity)));
}
}
我發現的代碼檢查複合材料項目同一塊在函數update_quantity_args(),add_to_cart()中。所以我也在那裏加入了我的改編。
我的代碼引發錯誤:在/.../wp-content/plugins/woocommerce-min-max-quantities/min-調用未定義的方法WC_Min_Max_Quantities_Addons :: wc_pb_is_bundled_cart_item():
致命錯誤max-quantities.php在線580
我試着將代碼從wc_pb_is_bundled_cart_item()
更新爲WC_Min_Max_Quantities_Addons::wc_pb_is_bundled_cart_item()
但是那樣會導致一個致命的錯誤。
所以有兩個問題:有沒有更簡單的方法去解決這個問題我沒有看到?如果沒有,我怎樣才能正確適應捆綁項目的複合項目補丁?
任何幫助非常感謝!
更新:
我已經添加了基於inarilo的建議基於類-WC-最小 - 最大-量-addons.php的is_composite_product()
函數調用is_bundled_product()
功能:
//original is is_composite_product() function:
public function is_composite_product($product_id) {
if (empty($product_id)) {
return false;
}
$product = wc_get_product($product_id);
if ('composite' === $product->product_type) {
return true;
}
return false;
}
//my function based on composite function:
public function is_bundled_product($product_id) {
if (empty($product_id)) {
return false;
}
$product = wc_get_product($product_id);
if ('bundle' === $product->product_type) {
return true;
}
return false;
}
這更新刪除了所有錯誤消息,但它仍然向用戶顯示警告,他們需要添加更多的單個項目以滿足最低/最高要求,因此它仍然不會刪除驗證以允許購買。
更新
我還試圖從順序規則不包括在包中的項目,但它仍然拋出購物車中的警告。
見圖片:excluding individual items
嘗試使用未登記「管理斯托克」產品頁面上。 http://prntscr.com/f4hj6a –
在捆綁物品產品頁面或單個物品上?我有管理的各個項目)股票 – Mark
你可以在'check_rules年初建議插件作者的一些類型的過濾器('方法....所以'如果(「複合」 === $產品 - >產品類型|| apply_filters(「wc_min_max_quantities_skip_rules」,虛假,$產品){返回true;}'然後,你可以篩選,從自己的插件 – helgatheviking