-1

Currently when I view one of my products and scroll down to read the description below the tabs and above the text I have input, it has a heading which simply says description when I look at the code it is as:

<h2>description</h2>

nothing complicated lol.

My question though, is how i can customise this heading to suit the products, I cannot find any documentation online other than removing it completely. I dont want to remove it, I want it to be Unique to the product.

For example, maybe adding a bit of code to functions.php that will tailor the heading to the product by using the brand and title for example.

in Yoast there are the options to use:

%%catogory%%%%sep%%%%title%%

Most products on my site have multiple categories so I would be looking for something like

%%brand%%%%sep%%%%title%% which would give the output - brand - title

I dont know if it is possible but any help would be greatly appreciated or even if there might be a suitable plugin.

@Shameem Ali P.K Provided the code below:

add_filter( 'woocommerce_product_description_heading',
'product_description_tab', 10, 1 );

function product_description_tab( $title ) {
global $post, $product;
$categ = $product->get_categories();

return $categ.'-'. $post->post_title;
}

I have found from Yoast what I believe to be the way they call the brand from PWB Plugin as shown below:

public function get_product_var_brand() {
    $product = $this->get_product();
    if ( ! is_object( $product ) ) {
        return '';
    }
    $brand_taxonomies = array(
        'product_brand',
        'pwb-brand',
    );
    $brand_taxonomies = array_filter( $brand_taxonomies, 'taxonomy_exists' );
    $primary_term = $this->search_primary_term( $brand_taxonomies, $product );
    if ( $primary_term !== '' ) {
        return $primary_term;
    }
    foreach ( $brand_taxonomies as $taxonomy ) {
        $terms = get_the_terms( $product->get_id(), $taxonomy );
        if ( is_array( $terms ) ) {
            return $terms[0]->name;
        }
    }
    return '';
}

I have tried different things but am unsure how to combine the two to give the desired outcome stated above.

closed as off-topic by Michael, Krzysiek Dróżdż, Jacob Peattie, Mark Kaplun, Max Yudin May 7 '18 at 13:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

You can change the description tab heading to the product category followed by the name using the following snippet

add_filter( 'woocommerce_product_description_heading', 'product_description_tab', 10, 1 );

function product_description_tab( $title ) {
global $post, $product;
$categ = $product->get_categories();

return $categ.'-'. $post->post_title;
}

According to above code, you can get product brand. I hope that'll solve your issue. let me know the result.

  • Thanks a lot for your help. That code works great, however it returns the category. I have been looking online to find out how to get the brand from the Perfect Woocommerce Brands plugin as opposed to the category. Have you any idea how i might do that or where to find the information – SupGen May 5 '18 at 21:32
  • I have tried replacing the bottom 2 lines with $brands = wp_get_post_terms( get_the_ID(), 'pwb-brand'); return $brands.' - '. $post->post_title; but I get array instead of the brand name – SupGen May 5 '18 at 21:53
  • - I have added code above. I was wondering if you or anyone else might know how to combine. I have included the code you have supplied here – SupGen May 5 '18 at 22:45
  • Did issue solve or not? – Shameem Ali May 6 '18 at 6:42
  • The product name is now showing. The code yo provided site the categories, I need the band, so the code did with but it just requires a slight tweak to be what I need – SupGen May 6 '18 at 9:59
0

Thanks for the down vote from whoever was nice enough to downvote and run...

I have figured out how to do it... so if anyone else has the same issue, this is what worked for me:

add_filter( 'woocommerce_product_description_heading','product_description_tab', 10, 1 );

function product_description_tab( $title ) {
global $post, $product;
$brands = wp_get_post_terms( get_the_ID(), 'pwb-brand' );
    foreach( $brands as $brand ) 
return $post_excerpt = $brand->name.' - '. $post->post_title;
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.