Home Forums Theme Support Dokan get seller ID, get_user_by, woocommerce_payment_complete

This topic is: resolved

This topic contains 2 replies, has 2 voices, and was last updated by  towhid 3 years, 10 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #54642

    Bryan
    Member
    Post count: 20

    I am attempting to get the sellers ID during this hook:

    I cannot figure out a good way to get this done here is what I am doing so far. I have a custom table that I am using that uses the seller id as one of the keys and updates the table.

    Here is my code:

    function ws_update_table($order_id) {
    	// if any child orders found, change the orders as well
    	$sub_orders = get_children( array( 'post_parent' => $order_id, 'post_type' => 'shop_order' ) );
        if ( $sub_orders ) {
            foreach ($sub_orders as $sub) {
                $order = new WC_Order( $sub->ID );
    			
    			//get the order items
    			$order_item = $order->get_items();
    			
    			foreach( $order_item as $item_id => $product ) {
    				global $wpdb;
    				//get values for vars
    				
    				$seller = get_user_by( 'id', $product->post->post_author );
    				//Update tables
    				$table = $wpdb->prefix . 'table';
    				$results = $wpdb->query("UPDATE ".$table." SET this = 'that' WHERE (seller_id = '".$seller."')", ARRAY_A);
    			}
            }
        }
    }
    add_action('woocommerce_payment_complete', 'ws_update_table', 10, 1);

    Also I have set $seller equal to a seller ID , e.g. $seller = '1'; which successfully updated the table for the seller with the ID of 1. Please help me get the sellers ID, thank you.

    #54646

    Bryan
    Member
    Post count: 20

    I solved the problem. I used the following code to set the seller variable

    $seller = dokan_get_seller_id_by_order( $sub->ID );

    I hope this helps someone.

    #54723

    towhid
    Participant
    Post count: 4505

    Hello Bryan,

    I am very happy that you have solved the problem. It will help someone if needed. I am going to mark this topic as resolved.

    Thanks

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘get seller ID, get_user_by, woocommerce_payment_complete’ is closed to new replies.