首页 文章

Woocommerce属性为 Headers

提问于
浏览
0

我正在使用woocommerce集成的wordpress网站 .

现在我想要覆盖具有相同项目的自定义属性值的项目 Headers (在产品 - 归档 - 页面和单一产品 - 页面上) .

我正在搞乱functions.php,但没有什么对我有用 .

这附近有什么woocommerce / .php专家吗?提前致谢!

1 回答

  • 2

    您需要使用 the_title 过滤器以及 in_the_loopis_shopis_product 条件,如下所示 . 将以下代码添加到主题的functions.php文件中

    add_filter( 'the_title', 'custom_the_title' );
    
    function custom_the_title( $title, $id ) {
    
        global $product;
    
        /*
         * We use is_shop and is_product to check if the page is product archive
         * or single product page. in_the_loop conditional is used to check if the loop
         * is currently active, otherwise it will over write the page title as well
         */
    
        if( ( is_shop() || is_product() ) && in_the_loop() ) {
    
            $attr = $product->get_attributes();
    
            // $attr contains the attribute array, apply the logic you need
            // and set $title 
    
            return $title;
    
        }
    
        return $title;
    }
    

相关问题