私は、(各商品ラインアイテムにデポジットを追加するのではなく)ウーコムスサイトのTOTALカート額にデポジットを追加する方法を探していました。例外付きの総カート数のパーセントに対するデフォルトデポジット
私はここで、この独創的なスレッドへの答えを見つけた:Deposit based on a percentage of total cart amount
は、ここに私が使用して終了コードです:
add_action('woocommerce_cart_calculate_fees', 'booking_deposit_calculation');
function booking_deposit_calculation($cart_object) {
if (is_admin() && ! defined('DOING_AJAX'))
return;
## Set HERE your negative percentage (to remove an amount from cart total)
$percent = -.50; // 50% off (negative)
// Get cart subtotal excluding taxes
$cart_subtotal = $cart_object->subtotal_ex_tax;
// or for subtotal including taxes use instead:
// $cart_subtotal = $cart_object->subtotal;
## ## CALCULATION ## ##
$calculated_amount = $cart_subtotal * $percent;
// Adding a negative fee to cart amount (excluding taxes)
$cart_object->add_fee(__('Deposit calculation', 'woocommerce'), $calculated_amount, false);
}
これは、カートとチェックアウトのすべての製品の50%の保証金のデフォルトを作成しますページ。ブリリアント! (CSSを使用して、私はフロントエンドの説明をスタイルすることができました)
しかし、私はこのデポジットを強制したくないいくつかの製品(1つの製品カテゴリー)を持っています。
だから、ここに私の質問です:
私は全体のカテゴリを除外することができない場合、デフォルトの預金を強制し続けるが、1つの製品カテゴリ(またはこのカテゴリーの製品から預金を除外するために、コードを微調整することができますどのように)?