[Gelöst] Display Custom Termfield for WooCommerce Category Pages
Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.
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 vor 2 Jahren, 5 Monaten. 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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
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
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.
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.
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.
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.