Home › Forums › Basel support forum › Show Attribute text (title) instead of image
Show Attribute text (title) instead of image
- This topic has 7 replies, 3 voices, and was last updated 6 years, 7 months ago by Elise Noromit.
-
AuthorPosts
-
May 1, 2018 at 4:10 pm #55598
antonchaik88ParticipantIf I use brands and choose to “Show attribute on product page” it will show the logo I assigned to it. I want it to show the brand name, or title, instead. How can I do that?
May 2, 2018 at 7:02 am #55638
Eric WatsonParticipantHello,
Could you explain in more detail or provide a screenshot, where exactly do you want to change the image to the title?
Kind Regards
XTemos StudioMay 3, 2018 at 5:12 am #55756
antonchaik88ParticipantI really don’t know how to be any more descriptive. Your theme offers brands. When brands are enabled, the brand logo shows up on product pages. I want the brand AND title to show up, not just the brand.
Theme Settings-> Shop -> Brands
May 3, 2018 at 6:25 am #55762
Eric WatsonParticipantHello,
Try to add the following PHP code snippet to the child theme functions.php file to do this
function basel_product_brand() { global $product; $attr = basel_get_opt( 'brands_attribute' ); if( ! $attr || ! basel_get_opt( 'product_page_brand' ) ) return; $attributes = $product->get_attributes(); if( ! isset( $attributes[ $attr ] ) || empty( $attributes[ $attr ] ) ) return; $brands = wc_get_product_terms( $product->get_id(), $attr, array( 'fields' => 'all' ) ); if( empty( $brands ) ) return; if ( defined( 'SHOP_IS_ON_FRONT' ) ) { $link = home_url(); } else { $link = get_post_type_archive_link( 'product' ); } echo '<div class="basel-product-brands">'; foreach ($brands as $brand) { $image = basel_tax_data( $brand->taxonomy, $brand->term_id, 'image' ); $filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $attr ) ); $attr_link = add_query_arg( $filter_name, $brand->slug, $link ); echo '<div class="basel-product-brand">'; echo '<a href="' . esc_url( $attr_link ) . '">' . esc_html( $brand->name ) . '</a>'; echo '</div>'; } echo '</div>'; }
Kind Regards
XTemos StudioMay 4, 2018 at 3:11 am #55941
antonchaik88ParticipantHello,
I see this puts the title where the product brand logo used to be, which is good.
However, I would also like to show the it on each shop product page, not single product page.This is inside the “product-labels labels-rectangular” div, as an added span element I suppose.
May 4, 2018 at 6:42 am #55957
Eric WatsonParticipantHello,
Try to add the following PHP code snippet to the child theme functions.php file to do this
function basel_get_product_attributes_label(){ global $product; $attributes = $product->get_attributes(); $output = array(); foreach ( $attributes as $attribute ) { if ( !isset( $attribute['name'] ) ) continue; $show_attr_on_product = basel_wc_get_attribute_term( $attribute['name'], 'show_on_product' ); if ( $show_attr_on_product == 'on' ) { $terms = wc_get_product_terms( $product->get_id(), $attribute['name'], array( 'fields' => 'all' ) ); foreach ( $terms as $term ) { $content = esc_attr( $term->name ); $classes = 'label-term-' . $term->slug; $classes .= ' label-attribute-' . $attribute['name']; $output[] = '<span class="attribute-label product-label ' . esc_attr( $classes ) . '">'. $content .'</span>'; } } } return $output; }
Kind Regards
XTemos StudioMay 10, 2018 at 4:53 am #56831
antonchaik88ParticipantThat worked thank you!
May 10, 2018 at 8:25 am #56880
Elise NoromitMemberYou are welcome! If you have any questions feel free to contact us.
Best Regards
-
AuthorPosts
Tagged: attribute brand
The topic ‘Show Attribute text (title) instead of image’ is closed to new replies.
- You must be logged in to create new topics. Login / Register