• Resolved joannapl

    (@joannapl)


    I am asking for help in adapting the woocommerce code.

    The main goal is if the user buys (after payment) Membership Levels id = 1 something has happened, and if id = 2 he will do something else.

    It just needs to add points to terawallet depending on the access level purchased.
    I do not know how to check so that it works right after the payment and how to check what package he bought in a given order.

    function auto_topup_user_on_product_purchase( $order_id ) {
        $order = new WC_Order($order_id);
    
         $customer_id = $order->get_customer_id(); // <=== Customer ID (if needed)
        $order_items = $order->get_items(); // <=== Grab all items in order
    
        $item_details = [];
    
        foreach ( $order_items as $item ) {
            // Get the ID of each item in Order
            $product_id = $item->get_product_id();
            $item_details[] = [
                'product_name'  => $item->get_name(),
                'purchaser'     => $order->get_customer_id(), 
            ];
        }
    
        
        foreach ($item_details as $item_detail) {
            $wallet = new Woo_Wallet_Wallet();
    
                    // Get purchaser's Percentage
            $purchasersCut = 75; // <=== purchaser Takes 80%
    
         if ( $product_id == '103' ) {
                
                $topUppurchaser = $wallet->credit($item_detail['purchaser'], $purchasersCut, "Top-Up from {$item_detail['product_name']} purchase");}
    	}    
    }
    add_action( 'woocommerce_order_status_completed', 'auto_topup_user_on_product_purchase', 10, 1 );
    • This topic was modified 3 years, 1 month ago by joannapl.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Code adaptation woocomerce after payment’ is closed to new replies.