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: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){
@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 / 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');
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;
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 / 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;
@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;
}
}