Skip to content

Instantly share code, notes, and snippets.

View malsubrata's full-sized avatar

Subrata Mal malsubrata

View GitHub Profile
@malsubrata
malsubrata / Wallet top up with coupon
Last active February 21, 2018 01:24
Wallet top up with WooCommerce coupon
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 {
@malsubrata
malsubrata / WooCommerce Currency Switcher
Last active June 11, 2021 12:25
Aelia Currency Switcher for WooCommerce Support (Multi currency)
add_filter('woo_wallet_amount', 'woo_wallet_amount_callback', 10, 2);
add_filter('woo_wallet_current_balance', 'woo_wallet_current_balance_callback', 10, 2);
if (!function_exists('woo_wallet_current_balance_callback')) {
function woo_wallet_current_balance_callback($balance, $user_id) {
$credit_amount = $debit_amount = 0;
$credit_array = get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'credit')), 'nocache' => true));
foreach ($credit_array as $credit) {
$credit_amount += get_terawallet_converted_amount($credit->amount, $credit->currency);
@malsubrata
malsubrata / restrict_cashback.php
Last active May 10, 2018 09:39
Restrict cashback for COD payment method
add_filter('process_woo_wallet_general_cashback', 'process_woo_wallet_general_cashback_callback', 10, 2);
function woo_wallet_general_cashback_amount($precess, $order){
if('cod' === $order->get_payment_method('edit')){
return false;
}
return $precess;
}
@malsubrata
malsubrata / _paypal_partial_payment.php
Last active May 1, 2018 06:56
Patch for paypal partial payment
add_filter('woocommerce_paypal_args', 'woocommerce_paypal_args_callback', 10, 2);
function woocommerce_paypal_args_callback($args, $order) {
if (isset($args['shipping_1']) && get_post_meta($order->get_id(), '_via_wallet_payment', true)) {
$_original_order_amount = get_post_meta($order->get_id(), '_original_order_amount', true);
$_via_wallet_payment = get_post_meta($order->get_id(), '_via_wallet_payment', true);
$via_paypal = $_original_order_amount - $_via_wallet_payment;
if ($args['shipping_1'] > $via_paypal) {
$args['shipping_1'] = $via_paypal;
$item_name = _get_order_item_names($order);
add_filter('woo_wallet_current_balance', 'woo_wallet_current_balance', 10, 2);
if(!function_exists('woo_wallet_current_balance')){
function woo_wallet_current_balance($balance, $user_id){
$credit_amount = array_sum(wp_list_pluck(get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'credit')), 'nocache' => true)), 'amount'));
$debit_amount = array_sum(wp_list_pluck(get_wallet_transactions(array('user_id' => $user_id, 'where' => array(array('key' => 'type', 'value' => 'debit')), 'nocache' => true)), 'amount'));
$balance = $credit_amount - $debit_amount;
return $balance;
}
}
@malsubrata
malsubrata / avada_cashback_patch.php
Created July 29, 2018 08:52
Cashback display patch for avada theme
add_action('init', 'init_woo_wallet_hooks');
function init_woo_wallet_hooks(){
if(!is_admin() && class_exists('Woo_Wallet_Frontend')){
remove_action('woocommerce_before_single_product_summary', array(Woo_Wallet_Frontend::instance(), 'display_cashback'), 15);
add_action('woocommerce_single_product_summary', array(Woo_Wallet_Frontend::instance(), 'display_cashback'), 15);
}
}
@malsubrata
malsubrata / mini-wallet-shortcode.php
Created October 2, 2018 07:33
Mini wallet shortcode
function woo_mini_wallet_callback() {
if (!function_exists('woo_wallet') || !is_user_logged_in()) {
return '';
}
ob_start();
$title = __('Current wallet balance', 'woo-wallet');
$mini_wallet = '<a class="woo-wallet-menu-contents" href="' . esc_url(wc_get_account_endpoint_url(get_option('woocommerce_woo_wallet_endpoint', 'woo-wallet'))) . '" title="' . $title . '">';
$mini_wallet .= '<span class="woo-wallet-icon-wallet"></span>';
$mini_wallet .= woo_wallet()->wallet->get_wallet_balance(get_current_user_id());
$mini_wallet .= '</a>';
@malsubrata
malsubrata / credit-purchase-status.php
Created October 13, 2018 06:27
Credit purchase status
add_filter('wallet_credit_purchase_order_status', 'wallet_credit_purchase_order_status');
function wallet_credit_purchase_order_status($status){
$status = array('completed');
return $status;
}
@malsubrata
malsubrata / disable_bacs_if_enable_partial_payment
Created January 9, 2019 06:36
Disable bank transfer if partial payment enabled
add_filter('woocommerce_available_payment_gateways', 'woocommerce_available_payment_gateways_callback');
if(!function_exists('woocommerce_available_payment_gateways_callback')){
function woocommerce_available_payment_gateways_callback($_available_gateways){
if(isset($_available_gateways[ 'bacs' ]) && is_enable_wallet_partial_payment()){
unset($_available_gateways[ 'bacs' ]);
}
return $_available_gateways;
}
}
@malsubrata
malsubrata / pay_only_with_wallet.php
Created March 7, 2019 12:48
Disable all other payment gateways if not wallet rechargeable cart.
if(!function_exists('woocommerce_available_payment_gateways_callback')){
function woocommerce_available_payment_gateways_callback($_available_gateways){
if(!is_admin() && !is_wallet_rechargeable_cart()){
foreach ($_available_gateways as $id => $gateway){
if('wallet' != $id){
unset($_available_gateways[$id]);
}
}
}
return $_available_gateways;