Skip to content

Instantly share code, notes, and snippets.

View malsubrata's full-sized avatar

Subrata Mal malsubrata

View GitHub Profile
@malsubrata
malsubrata / wallet-referral-link.php
Created December 28, 2023 15:30
Display TeraWallet referral link shortcode
@malsubrata
malsubrata / wallet-payment-for-manual-orders.php
Created January 18, 2023 13:03
Auto deduct wallet balance while creating orders from backend.
add_action( 'woocommerce_update_order', 'woocommerce_update_order_callback' );
if ( ! function_exists( 'woocommerce_update_order_callback' ) ) {
/**
* Auto deduct wallet balance while creating orders from backend.
*
* @param integer $order_id Order ID.
* @return void
*/
function woocommerce_update_order_callback( $order_id ) {
$order = wc_get_order( $order_id );
@malsubrata
malsubrata / gist:a84b8a6eae0f02873d9c7d576f5c7ec1
Created May 12, 2022 15:19
terawallet-transactions-shortcode
add_shortcode('terawallet-transactions', 'terawallet_transaction_shortcode');
if(!function_exists('terawallet_transaction_shortcode')){
function terawallet_transaction_shortcode(){
wp_enqueue_style('woo-wallet-payment-jquery-ui');
wp_enqueue_style('dashicons');
wp_enqueue_style('select2');
wp_enqueue_style('jquery-datatables-style');
wp_enqueue_style('jquery-datatables-responsive-style');
wp_enqueue_script('jquery-ui-datepicker');
@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 / terawallet-topup-shortcode.php
Last active November 28, 2022 21:06
TeraWallet TopUp shortcode
add_shortcode('terawallet-topup', 'terawallet_topup_shortcode');
function terawallet_topup_shortcode(){
ob_start();
?>
<form method="post" action="">
<div class="woo-wallet-add-amount">
<label for="woo_wallet_balance_to_add"><?php _e( 'Enter amount', 'woo-wallet' ); ?></label>
<?php
$min_amount = woo_wallet()->settings_api->get_option( 'min_topup_amount', '_wallet_settings_general', 0 );
@malsubrata
malsubrata / terawallet-transfer-shortcode.php
Last active November 28, 2022 21:06
TeraWallet Transfer Shortcode
add_shortcode('terawallet-transfer', 'terawallet_transfer_shortcode_callback');
if (!function_exists('terawallet_transfer_shortcode_callback')) {
function terawallet_transfer_shortcode_callback($atts) {
ob_start();
wc_print_notices();
if (!is_user_logged_in()) {
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
@malsubrata
malsubrata / gist:402add32013a8351b67923e51334a5fa
Created August 30, 2022 16:02
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){
if (!function_exists('points_to_wallet_balance_convertion_shortcode_func')) {
function points_to_wallet_balance_convertion_shortcode_func($atts) {
$atts = shortcode_atts(
array(
'convertion_rate' => 1
), $atts, 'convert_points_to_wallet_balance' );
if(!is_user_logged_in()){
return __('Please login');
}
$user = wp_get_current_user();
@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);
add_filter('is_enable_wallet_partial_payment', '__return_true');
add_filter('is_valid_payment_through_wallet', '__return_false');
add_filter('woo_wallet_partial_payment_amount', 'woo_wallet_partial_payment_amount_callback', 10);
function woo_wallet_partial_payment_amount_callback($amount) {
if (sizeof(wc()->cart->get_cart()) > 0) {
$cart_total = get_woowallet_cart_total();
$partial_payment_amount = ($cart_total * 20) / 100;
if ($amount >= $partial_payment_amount) {
$amount = $partial_payment_amount;