hi @cupcakes99
To check if there is a store credit available for the current user, you may check out this snippet
function get_user_store_credits($user_id) {
// Replace 'store_credits' with the actual meta key used by your store credit system
$credits = get_user_meta($user_id, 'acfw_store_credit_balance', true);
return $credits ? $credits : 0;
}
// Example usage:
$user_id = get_current_user_id(); // or any specific user ID
echo 'Store Credits: ' . get_user_store_credits($user_id);
For you inquiry in checking coupons is connected to the user, this one is a bit tricky. In WooCommerce, the coupon is not directly connected to the users, but rather in products/cart. You may only check if the coupon is connected to the users if they have already used the coupon from previous orders.
You may still want to try it out using this code:
function is_coupon_used_by_user($coupon_code, $user_id) {
// Get all orders of the user
$orders = wc_get_orders(array(
'customer' => $user_id,
'status' => array('wc-completed', 'wc-processing') // Modify statuses as needed
));
foreach ($orders as $order) {
// Check if the coupon is used in the order
$used_coupons = $order->get_used_coupons();
if (in_array($coupon_code, $used_coupons)) {
return true;
}
}
return false;
}
// Example usage:
$coupon_code = 'COUPON_CODE'; // Replace with your coupon code
$user_id = get_current_user_id(); // Replace with specific user ID
if (is_coupon_used_by_user($coupon_code, $user_id)) {
echo 'The coupon is used to this user.';
} else {
echo 'The coupon is not used to this user.';
}
I hope this helps.
Cheers!