はい、あなたは(クーポンのセットのために)そのスニペットコードでそれを行うことができます。
function coupon_add_cart_fee($bookable_total = 0) {
$has_coupon = false;
// Set here your specials coupons slugs (one by line - last one have no coma)
$coupon_codes = array (
'your_coupon_code_slug1',
'your_coupon_code_slug2',
'your_coupon_code_slug3'
);
// Set here your fee amount or make fees calculation (see the links in reference)
$fee = 20;
if (is_admin() && ! defined('DOING_AJAX'))
return;
// checking if that "special" coupon is applied to customer cart
foreach ($coupon_codes as $coupon_code) {
if (WC()->cart->has_discount($coupon_code)) {
// If yes apply the fee to the cart
if (!$has_coupon) {
$has_coupon = true;
break;
}
}
}
if ($has_coupon) {
WC()->cart->add_fee('Fees: ', $fee, false);
}
}
add_action('woocommerce_cart_calculate_fees','coupon_add_cart_fee');
このコードがテストされ、それが動作します。あなたのアクティブな子テーマまたはテーマのfunction.phpファイルに移動します。
add_fee() method
重要とTAXオプション: TAX がadd_fee()
methodでを働いたりされていないという事実は、woocommerceであなたの税金設定のが最初に依存します。
クラスWC_Cart add_fee()メソッドは、カートに追加料金を追加します。
add_fee(string $name, float $amount, boolean $taxable = false, string $tax_class = '' )> <!-- language: lang-css -->
Parameters:
$name Unique name for the fee. Multiple fees of the same name cannot be added.
$amount Fee amount.
$taxable (default: false) Is the fee taxable?
$tax_class (default: '') The tax class for the fee if taxable. A blank string is standard tax class.
参考:
これは私が必要とする、幻想的で正確なものです@LoicTheAztec。これはもっと基本的なPHPの問題かもしれませんが、 'coupon_code'変数にクーポンコードの配列を格納することはできますか?多くのコードのいずれかが利用されている場合は追加する必要がありますか? – Cmagb
単一クーポン値で完全にテストされています。アレイのおかげで、ありがとう。あなたの助けが大いにありがとう!間違いなくここでたくさんのことを学ぶ。 – Cmagb