Skip Navigation

[Resolved] Display Custom Termfield for WooCommerce Category Pages

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user wanted to use their custom field value that's on the taxonomy as their Product Archive Title.

Solution:

This can be done by using the Hook below.

add_filter( 'woocommerce_page_title', 'customize_woocommerce_page_title', 10, 1 );
function customize_woocommerce_page_title( $page_title) {
$new_title = types_render_termeta( "my-field", array() );
// Custom title for the product category
if ( is_product_category() && !empty($new_title) ) {
$page_title = types_render_termeta( "my-field", array() );
}
return $page_title;
}

replace my-field with the slug of your custom field.

Add the code to your custom code options at Toolset->Settings -> Custom Code and activate it.

This support ticket is created 2 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 13 replies, has 2 voices.

Last updated by christophS-4 2 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#2406003
Bildschirmfoto 2022-06-27 um 13.40.17.png
Bildschirmfoto 2022-06-27 um 13.39.57.png

Tell us what you are trying to do?

I want to display a Custom title on woocommerce archive/category pages.

So i created a Cusomt Term field and i can see it in the archive / category edit window on backend.
how can i display it on the frontend after / instead of the standard title?

i use shoptimizer theme.

Is there any documentation that you are following?
No

Is there a similar example that we can see?

What is the link to your site?
hidden link

#2406177

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christoph,

Thank you for getting in touch.

Are you using a Custom Archive Template to create the woocommerce product archive ?

If so then you can just use the shortcode below to do this.
[types termmeta='field_slug'][/types]

Thanks,
Shane

#2406185

Hi Shane

No i want just to use a simple hook.

#2406189

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christoph,

You can perhaps try the hook below.

add_filter( 'get_the_archive_title', function ( $title ) {

    if( is_category() ) {

        $title = types_render_termeta( "my-field", array() );

    }

    return $title;

});

However you will need to replace "my-field" with the slug of your field. If this hook doesn't work then you will perhaps need to consult with the Woocommerce support team to see how best you can replace the title with the custom field as the types_render_termeta() function is used to get the custom field value in php.

Thanks,
Shane

#2406195

I add this to function.php:

add_filter( 'get_the_archive_title', function ( $title ) {


    if( is_category() ) {
        $title = types_render_termeta( "eigener-kategorie-titel", array() );
    }

    return $title;

});

But the Field is not display on the category page.

#2406225

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christoph,

I checked for a Woocommerce specific function and found this.

add_filter( 'woocommerce_show_page_title', ' modify_category_title_from_product_archive' );
function modify_category_title_from_product_archive( $title ) {
if ( is_product_category() ) {
$title = false;
}
return $title;
}

PLease let me know if the above removes the title. If it does then use the modification below.


add_filter( 'woocommerce_show_page_title', ' modify_category_title_from_product_archive' );
function modify_category_title_from_product_archive( $title ) {
if ( is_product_category() ) {
$title = types_render_termeta( "eigener-kategorie-titel", array() );
}
return $title;
}

Thanks,
Shane

#2406231

Hmm nope dont work.

#2406379

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christoph,

Would you mind allowing me to have admin access to the website so that I can have a more detailed look at this for you ?

Please where applicable please provide me with a link to an example page where I can see the issue.

I've enabled the private fields for your next response.

Thanks,
Shane

#2406951

U can login here:

hidden link

Here is the Place where i placed the snippet:
hidden link

And here the Link for the Toolset Termfield:
hidden link

#2407139

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christoph,

At this point i'm at a loss. All the indications point to the "woocommerce_show_page_title" hook but so far it has failed to modify the title of the page.

What I recommend here is that you get in touch with the Woocommerce support team for them to check to see why this hook isn't working.

Thanks,
Shane

#2407209

Hey i just figured out something what works:

add_filter( 'woocommerce_page_title', 'customize_woocommerce_page_title', 10, 1 );
function customize_woocommerce_page_title( $page_title) {

// Custom title for the product category
if ( is_product_category() ) {
$page_title = 'Something';
}
return $page_title;
}

But now the 'Something' should render the custom term field.

#2407213

I got it when i use it with shortcode:
add_filter( 'woocommerce_page_title', 'customize_woocommerce_page_title', 10, 1 );
function customize_woocommerce_page_title( $page_title) {

// Custom title for the product category
if ( is_product_category() ) {
$page_title = do_shortcode( '[types termmeta="eigener-kategorie-titel"][/types]' );
}
return $page_title;
}

but why it dont work the firstway?
And if the field"eigener-kategorie-titel' is empty it should return normal page title ... thats missing.

#2407311

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Christoph,

Happy to see you were able to find a hook that works.

but why it dont work the firstway?

Not sure what you mean by this, however if you're referring to the Hook then this is a completely different hook that the one I found on the woocommerce docs.


add_filter( 'woocommerce_page_title', 'customize_woocommerce_page_title', 10, 1 );
function customize_woocommerce_page_title( $page_title) {
$new_title = do_shortcode( '[types termmeta="eigener-kategorie-titel" output='raw'][/types]' );
// Custom title for the product category
if ( is_product_category() && !empty($new_title) ) {
$page_title = do_shortcode( '[types termmeta="eigener-kategorie-titel"][/types]' );
}
return $page_title;
}

If you use the above code it should now account for if the field value is missing.

Thanks,
Shane

#2409157

My issue is resolved now. Thank you!