ユーザーが初めて注文する場合、税額が計算される前にカート小計に割引を適用する必要があります。ただし、税はWooCommerceのアイテムごとに計算され、その後は小計に加算されます。 したがって、WooCommerceが税金を計算する前にカート内のアイテムに割引を適用する必要があります。このように、税金は元の価格ではなく割引価格に基づいています。ここでWooCommerceで税別を除外したカート内容合計に割引を適用
は私が持っているものです。
function first_order_add_five_percent_discount($cart_object) {
if (is_user_logged_in()) {
//current user id
$currentUser_id = get_current_user_id();
//amount of orders by current user
$orderAmount = wc_get_customer_order_count($currentUser_id);
//if user has 0 orders...
if ($orderAmount == 0) {
//for each item in cart
foreach ($cart_object->get_cart() as $item_values) {
//$item_id = $item_values['data']->id; // Product ID
$item_qty = $item_values['quantity']; // Item quantity
$original_price = $item_values['data']->price; // Product original price
echo $original_price . "<br>";
$totalPrice = $original_price * $item_qty;
$discountedPrice = $totalPrice * .05;
$newPrice = $original_price - $discountedPrice;
echo $totalPrice . "<br>";
echo $discountedPrice . "<br>";
echo $newPrice . "<br>";
$item_values['data']->set_price($newPrice);
}
} else {
//do nothing
}
}
}
add_action('woocommerce_before_calculate_totals', 'first_order_add_five_percent_discount');
これは私が必要とする右の数字をエコー表示が、今私はカートにそれらの価格を適用する必要があります。今、カートの価格は変わらない。
この機能の計算による新しい価格をカートにどのように適用できますか?
遅れて申し訳ありませんが、別の奇妙な税金関連の問題に取り組んでいました。しかし、はい、これは正しいです!割引が適用された後、税金が計算されます。完璧な感謝です。 –