Overrride "display_format" for vendor attribute if checkbox type

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
);

Hi,

  1. The location attribute is displayed via a template part instead of display format, you can override it via a child theme hivepress-geolocation/templates/vendor/view/vendor-location.php at master · hivepress/hivepress-geolocation · GitHub

  2. There’s an extra space in the array key 'display_format ', maybe this causes the issue.

Hope this helps

Thanks for reply, and info about how to override the location attribute and will give that suggestion a try.

There’s an extra space in the array key 'display_format ', maybe this causes the issue.

This was just a typo here in the post, and can confirm it was not the reason. I think it is not working as our custom attribute(offered_payment_methods) is a checkbox type, which is why split the code into two functions. One for single value attributes, and the second as assume it might work differently for checkbox or dropdowns. But as said earlier I can’t find documentation to point me in right direction.

Please try changing the callback priority, the checkbox display format works in the same way, the only difference is that it replaces %value% with Yes or No.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.