• Resolved brunosl1

    (@brunosl1)


    Hello,

    I created two extra fields for the vendors settings and i′ts working.

    Now i need get $vendor_id before checkout to load email and token from fields, it′s working when i force a correct id.

    But i can′t get current store vendor_id, i trying these ways but the id not is correct vendor_id

    $vendor_id = get_post_field( ‘post_author’, get_the_id() );
    $vendor_id = get_current_vendor_id();

    What′s the way to get this information?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WC Lovers

    (@wclovers)

    Hi,

    $vendor_id = get_post_field( ‘post_author’, get_the_id() );
    $vendor_id = get_current_vendor_id();

    – Definitely this will not work.

    Well, at checkout there may be many items from different vendors. So you have to fetch all those items’ vendor id, right?

    Thank You

    Thread Starter brunosl1

    (@brunosl1)

    Hello thank you for support.

    No i blocked in add_cart to allow add only products for same vendor.

    Plugin Author WC Lovers

    (@wclovers)

    Hi,

    OK, you have to use such code to retrieve cart item vendor id –

    $vendor_id = 0;
    	if( function_exists( 'is_checkout' ) && is_checkout() ) {
    		foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    			$cart_product_id = $cart_item['product_id'];
    			$cart_product = get_post( $cart_product_id );
    			$cart_product_author = $cart_product->post_author;
    			if( function_exists( 'wcfm_is_vendor' ) && wcfm_is_vendor( $cart_product_author ) ) $vendor_id = $cart_product_author;
    			break;
    		}	
    	}

    Thank You

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Vendor_id before checkout’ is closed to new replies.