[英]Display ACF field/image below the product title in WooCommerce archive pages
[英]Replace Woocommerce taxonomy archive pages title with ACF custom field
我想弄清楚如何用ACF字段替换“ woocommerce_page_title”? 如果没有,则应退回到“ woocommerce_page_title();”。 我似乎找不到任何超级有用的东西。 您的帮助将不胜感激。
add_filter( 'woocommerce_page_title', 'custom_title' );
function custom_title( $title ) {
$title = get_field("custom_tag_h1");
return $title;
}
对于“档案”页面分类标题和ACF:
woocommerce_page_title
适用于商店页面和分类归档页面,因此在ACF中:
然后在一个产品类别(例如“服装”)中 ,设置自定义标题:
在代码中,您需要获取分类档案页面的查询对象( WP_Term
对象)并将其设置如下:
add_filter( 'woocommerce_page_title', 'custom_title' );
function custom_title( $page_title ) {
if ( ! function_exists('get_field') || is_search() )
return $page_title;
if ( is_tax() ) {
$term = get_queried_object();
$the_id = $term->taxonomy . '_' . $term->term_id;
} elseif ( is_shop() ) {
$the_id = wc_get_page_id( 'shop' );
}
return get_field( "custom_tag_h1", $the_id ) ? get_field( "custom_tag_h1", $the_id ) : $page_title;
}
代码进入您的活动子主题(或活动主题)的function.php文件中。 经过测试和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.