I am trying to hide certain Vendor attributes from showing on the vendor page if user is not logged in but getting mixed results (as seen in below screenshot).
The below code works for the two custom text/phone type of attributes (‘vendor_phone_number’ and ‘bank_account_info’), but not for vendor attribute ‘location’.
And then the 2nd function is not working for overriding the output of ‘offered_payment_methods’, and not sure how to adjust since it is a checkbox type attribute.
Struggling to find documentation on this, so please can I get some help. Thanks.
add_filter(
'hivepress/v1/models/vendor/attributes',
function( $attributes ) {
// List of attributes to update
$attribute_text = ['location', 'vendor_phone_number', 'bank_account_info'];
// Loop through each attribute and update the display format if it exists
foreach ( $attribute_text as $key ) {
if ( isset( $attributes[ $key ] ) && !is_user_logged_in() ) {
$attributes[ $key ]['display_format'] = '<strong>' . ucwords(str_replace('_', ' ', $key)) . ':</strong> <span class="login-to-view">(login to view)</span>';
}
}
return $attributes;
},
1000
);
add_filter(
'hivepress/v1/models/vendor/attributes',
function( $attributes ) {
// List of attributes to update
$attribute_checkbox = ['offered_payment_methods'];
// Loop through each attribute and update the display format if it exists
foreach ( $attribute_checkbox as $key ) {
if ( isset( $attributes[ $key ] ) && !is_user_logged_in() ) {
$attributes[ $key ]['display_format '] = '<strong>' . ucwords(str_replace('_', ' ', $key)) . ':</strong> <span class="login-to-view">(login to view)</span>';
}
}
return $attributes;
},
1000
);