如何在 woocommerce 的购物车页面上为每个供应商获取 vendor_ids

How to get the vendor_ids for each of the vendors with products on the cart page in woocommerce

global $woocommerce;
$items = $woocommerce->cart->get_cart();

foreach($items as $item => $values) { 
    $_product = $values['data']->post; 
    echo "<b>".$_product->post_title.'</b>  <br> Quantity: '.$values['quantity'].'<br>'; 
    $price = get_post_meta($values['product_id'] , '_price', true);
   echo "  Price: ".$price."<br>";

我使用以下方法获取有关购物车中产品的数据并显示出来。是否也有可能获得每种产品的供应商,我该如何在 woo commerce 中做到这一点?再次从购物车页面返回,因为我想在购物车页面上的每个产品下回显供应商地址。

  add_filter( 'woocommerce_get_item_data', 'wc_add_address_to_cart', 10, 2 ); 
function wc_add_address_to_cart( $other_data, $cart_item ) { 
    $post_data = get_post( $cart_item['product_id'] ); 
    $post_data->post_author; 
    $vendor_id = $post_data->post_author;
    echo '<br>';
    $Add = 'Address: ';
    $city = 'City: ';
    $tel = 'Phone: ';
    echo $test;
    $user_id = $vendor_id;

    // Get all user meta data for $user_id
    $meta = get_user_meta( $user_id );

    // Filter out empty meta data
    $meta = array_filter( array_map( function( $a ) {
        return $a[0];
    }, $meta ) );

    echo $Add;
    print_r( $meta ['_vendor_address_1'] );

    echo '<br>';

    echo $city;
    print_r( $meta['_vendor_city'] );

    echo '<br>';

    echo $tel;
    print_r( $meta['_vendor_phone'] ); 
    return $other_data; 

} 

终于找到我要找的东西了。只需将其添加到 functions.php