Last active
February 21, 2018 01:24
-
-
Save malsubrata/498f0dc8d54b7b758713bb7955d7b9a2 to your computer and use it in GitHub Desktop.
Wallet top up with WooCommerce coupon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woo_wallet_credit_purchase_amount', 'woo_wallet_credit_purchase_amount_callback', 10, 2); | |
function woo_wallet_credit_purchase_amount_callback($recharge_amount, $order_id) { | |
$order = wc_get_order($order_id); | |
$recharge_amount = $order->get_subtotal('edit'); | |
if ('on' === woo_wallet()->settings_api->get_option('is_enable_gateway_charge', '_wallet_settings_credit', 'off')) { | |
$charge_amount = woo_wallet()->settings_api->get_option($order->get_payment_method(), '_wallet_settings_credit', 0); | |
if ('percent' === woo_wallet()->settings_api->get_option('is_enable_gateway_charge', '_wallet_settings_credit', 'percent')) { | |
$recharge_amount -= $recharge_amount * ($charge_amount / 100); | |
} else { | |
$recharge_amount -= $charge_amount; | |
} | |
update_post_meta($order_id, '_wc_wallet_purchase_gateway_charge', $charge_amount); | |
} | |
return $recharge_amount; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment