無償で自己宣伝しますが、私のName Your Priceはミニカートで自動的に動作します。
しかし、あなたの質問は実際にアイテムがユニークであると考えられていない理由を実際に尋ねていると思うので、もう一度追加します。その答えは、異なる価格でユニークなものになることです。$cart_id
see source一意のIDを持つアイテムはカートに見つかりませんので、再度追加されます。
異なる販売価格の商品を個別に個別に販売するには、woocommerce_cart_id
をフィルタリングしてカートIDの生成方法を変更する必要があります。ここで私はあなたのPriceプラグインの名前で動作する方法です。それを自分のコードに適合させる必要があります。
<?php
/**
* Plugin Name: WooCommerce Name Your Price Sold Individually
* Plugin URI: https://gist.github.com/helgatheviking/a8802255167751a5dd746f83cdfc8716
* Description: Double check enforcement of "Sold Individually" for NYP items
* Version: 1.1.0
* WC requires at least: 2.6.3
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com/
*
* Copyright: © 2016 Kathy Darling
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
function wc_nyp_force_sold_individually($cart_id, $product_id, $variation_id, $variation, $cart_item_data) {
// Get the product
$product = wc_get_product($variation_id ? $variation_id : $product_id);
if ($product->is_sold_individually() && WC_Name_Your_Price_Helpers::is_nyp($product)){
$id_parts = array($product_id);
if ($variation_id && 0 != $variation_id) {
$id_parts[] = $variation_id;
}
if (is_array($variation) && ! empty($variation)) {
$variation_key = '';
foreach ($variation as $key => $value) {
$variation_key .= trim($key) . trim($value);
}
$id_parts[] = $variation_key;
}
$cart_id = md5(implode('_', $id_parts));
}
return $cart_id;
}
add_filter('woocommerce_cart_id', 'wc_nyp_force_sold_individually', 10, 5);