mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
16 lines
534 B
Text
16 lines
534 B
Text
//
|
|
add_action('woocommerce_cart_calculate_fees', 'apply_stripe_discount');
|
|
function apply_stripe_discount() {
|
|
if (is_admin() && !defined('DOING_AJAX')) {
|
|
return;
|
|
}
|
|
|
|
// Check if Stripe is the selected payment gateway
|
|
if (WC()->session->get('chosen_payment_method') === 'stripe') {
|
|
$cart_total = WC()->cart->get_cart_contents_total();
|
|
$discount_amount = $cart_total * 0.03; // 3% discount
|
|
|
|
// Add discount
|
|
WC()->cart->add_fee('Stripe Discount', -$discount_amount, true);
|
|
}
|
|
}
|