// Function to add store credit to a customer's account
function add_store_credit_to_customer($order, $customer_id, $amount, $reason ) {
require_once ABSPATH . 'wp-content/plugins/wt-woocommerce-gift-cards/common/modules/wallet/wallet.php';
require_once ABSPATH . 'wp-content/plugins/wt-woocommerce-gift-cards/common/class-wt-woocommerce-gift-cards-common.php';
if (class_exists('Wt_Gc_Wallet_Common')) {
// Instantiate the class from the other plugin
$wallet_instance = new Wt_Gc_Wallet_Common();
/*$order_user = $order->get_user();
$coupon_data = $wallet_instance->create_wallet_coupon($order_user, $amount);
$wallet_data = array('order_id' => $order->get_id(), 'added_via_giftcard_store_credit' => 1);
$wallet_instance->add_new_wallet_entry($customer_id, $amount, 'admin_credited', 0, $wallet_data);
// Call the method from the other plugin
// Do something with $result
} else {
// Class not found
// Handle the situation accordingly
}
*/
$order_user_id = $order->get_user_id();
$wallet_coupon_id = self::get_wallet_coupon_id($order_user_id);
if(!$wallet_coupon_id) /* No wallet coupon for the current user so create new */
{
$coupon_data = $wallet_instance->create_wallet_coupon($order_user, $amount);
if(empty($coupon_data)) //unable to create wallet coupon
{
return false;
}
}else
{
$wallet_coupon = new WC_Coupon($wallet_coupon_id);
$current_balance = Wt_Woocommerce_Gift_Cards_Common::get_coupon_amount( $wallet_coupon, 'edit' );
$new_balance = $current_balance + $amount;
/* set the amount */
$wallet_coupon->set_amount($new_balance);
$wallet_coupon->save();
//update balance amount meta
self::set_wallet_amounts($wallet_coupon_id, $new_balance, 'balance');
}
$wallet_data = array('order_id' => $order->get_id(), 'added_via_gidtcard_store_credit' => 1);
$this->add_new_wallet_entry($order_user_id, $amount, 'admin_credited', 0, $wallet_data);
return true;
}
Page not found - Dr. Eric Pearl - The Reconnection