I would suggest adding a “virtual” coupon to the order which would represent the store credit.
Coupons are applied on the cart page before checkout, this is where I would hook in.
You can use something like the woocommerce_cart_subtotal
filter as per my example below:
function royal_woocommerce_filter_checkout_for_coupons( $subtotal, $compound, $cart ) {
// Your logic to get store credit value for a user will go here
$store_credit = 20;
// We only need to add a store credit coupon if they have store credit
if($store_credit > 0){
// Setup our virtual coupon
$coupon_name="store-credit";
$coupon = array($coupon_name => $store_credit);
// Apply the store credit coupon to the cart & update totals
$cart->applied_coupons = array($coupon_name);
$cart->set_discount_total($store_credit);
$cart->set_total( $cart->get_subtotal() - $store_credit);
$cart->coupon_discount_totals = $coupon;
}
return $subtotal;
}
add_filter( 'woocommerce_cart_subtotal', 'royal_woocommerce_filter_checkout_for_coupons', 10, 3 );