Display author meta on WooCommerce product page

I am using the WooCommerce product Vendor plugin on my WP site. Each vendor got their own vendor profile. I want to display author meta such as LinkedIn, facebook, wikipedia etc. on each vendor product.

The social profiles data is stored in the regular WordPress user profile. If you create a new user on a WP installation you should see facebook profile URL, Wikipedia, LinkedIn etc. under the contact information form table. Each user therefore just enter their social profiles within their WordPress profile.

I am running into a dead-end in my code when I try to get user id from the title.

If I do var_dump( $vendor_data ); I get all of the user information I need:

array(1) { [63]=> array(21) { [“notes”]=> string(0) “” [“logo”]=> string(0) “” [“profile”]=> string(0) “” [“email”]=> string(0) “” [“admins”]=> array(1) { [0]=> int(20) } [“commission”]=> int(70) [“commission_type”]=> string(10) “percentage” [“paypal”]=> string(0) “” [“timezone”]=> string(5) “UTC+2” [“enable_bookings”]=> string(2) “no” [“per_product_shipping”]=> string(2) “no” [“instant_payout”]=> string(2) “no” [“term_id”]=> int(63) [“name”]=> string(9) “Tobias M.” [“slug”]=> string(8) “tobias-m” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(63) [“taxonomy”]=> string(20) “wcpv_product_vendors” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(2) } }

With the var_dump above I’ve changed line 11 to be:

$vendor_data[ $vendor_id ] = WC_Product_Vendors_Utils::get_vendor_data_by_id( $vendor_id )->name;`

However, I am running into a dead-end since this is giving me an error:

array(1) { [63]=> NULL } Warning: trim() expects parameter 1 to be string, array given in /app/public/wp-includes/class-wp-user.php on line 206

MY CODE:

add_action( ‘woocommerce_after_add_to_cart_button’, ‘our_vendor_info’ );
function our_vendor_info() {
if( is_product() ) {
// get the product id of the order item
$product_id = get_queried_object()->ID;

// get vendor id from product id
$vendor_id = WC_Product_Vendors_Utils::get_vendor_id_from_product( $product_id );

// get vendor data
$vendor_data[ $vendor_id ] = WC_Product_Vendors_Utils::get_vendor_data_by_id( $vendor_id )->name;

var_dump( $vendor_data );

// Now get user id from title
$user = get_userdatabylogin($vendor_data);

// Get social profiles
$wikipedia = get_the_author_meta( ‘wikipedia’, $user->ID );

echo ‘<div class=”large-3 columns venprofilelink”>’;
if (get_the_author_meta( ‘wikipedia’, $user->ID )) {
echo ‘<span class=”some-talent”><a href=”‘. $wikipedia .'” target=”blank” rel=”noopener noreferrer”><img src=”http://example.local/wp-content/uploads/2019/09/wikipedia-logo.svg” /></a></span>’;
} else {
echo ‘Hello World!’;
}
}
echo ‘</div>’;
}

Read more here:: Display author meta on WooCommerce product page

Leave a Reply

Your email address will not be published. Required fields are marked *