get seller ID, get_user_by, woocommerce_payment_complete

This topic contains 2 reply and 2 voices, and was last updated by towhid 9 years, 4 months ago
Viewing 2 Posts - 1 through 2 (of 2 total)
Author Posts
July 7, 2015 at 7:55 pm 54642
towhid 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.
July 7, 2015 at 8:22 pm 54646
Bryan Bryan

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.

July 8, 2015 at 12:24 pm 54723
towhid towhid

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 2 Posts - 1 through 2 (of 2 total)