Skip to content

Instantly share code, notes, and snippets.

@malsubrata
Created August 30, 2022 16:02
Show Gist options
  • Save malsubrata/402add32013a8351b67923e51334a5fa to your computer and use it in GitHub Desktop.
Save malsubrata/402add32013a8351b67923e51334a5fa to your computer and use it in GitHub Desktop.
Deduct wallet balance if order cancelled or failed
add_action('woocommerce_order_status_cancelled', 'debuct_wallet_recharge_amount');
add_action('woocommerce_order_status_failed', 'debuct_wallet_recharge_amount');
if(!function_exists('debuct_wallet_recharge_amount')){
function debuct_wallet_recharge_amount($order_id){
global $wpdb;
$order = wc_get_order($order_id);
$user_id = $order->get_customer_id();
if(is_wallet_rechargeable_order($order)){
$transaction_id = get_post_meta($order_id, '_wallet_payment_transaction_id', true);
if($transaction_id){
$update = $wpdb->update( "{$wpdb->base_prefix}woo_wallet_transactions", array('deleted' => 1), array( 'user_id' => $user_id ), array('%d'), array( '%d' ) );
if ( $update ) {
clear_woo_wallet_cache( $user_id );
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment