Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('processed_subscription_payment', 'custom_process_order', 10, 2);
- function custom_process_order($user_id, $subscription_key) {
- // split subscription key into order and product IDs
- $pieces = explode( '_', $subscription_key);
- $order_id = $pieces[0];
- $product_id = $pieces[1];
- // get order total
- $order = wc_get_order( $order_id );
- $amount = $order->get_total();
- // get current user's funds
- $funds = get_user_meta( $user_id, 'account_funds', true );
- $funds = $funds ? $funds : 0;
- $funds += floatval( $amount );
- // add funds to user
- update_user_meta( $user_id, 'account_funds', $funds );
- }
- add_action('woocommerce_subscription_payment_complete', 'action_subscription_payment_complete_callback', 10, 1);
- function action_subscription_payment_complete_callback( $subscription ) {
- // Get the instance WC_Order Object for the current subscription
- $order = wc_get_order( $subscription->get_parent_id() );
- $user_id = (int) $order->get_customer_id(); // Customer ID
- $total = (float) $order->get_total(); // Order total amount
- // Get customer existing funds (zero value if no funds found)
- $user_funds = (float) get_user_meta( $user_id, 'account_funds', true );
- // Add the order total amount to customer existing funds
- update_user_meta( $user_id, 'account_funds', $funds + $total );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement