根据PolyLang当前语言切换WooCommerce产品说明标题

时间:2017-12-08 05:01:06

标签: php wordpress function woocommerce polylang

此代码将网站上的英文(en)和泰国(产品)的描述标题更改为“属性”。但显然它只需要为英文版本返回,并返回泰国产品的'คุณลักษณะ'。

add_filter('woocommerce_product_description_heading','switch_product_description_heading');
     function switch_product_description_heading() {
     return 'Attributes';
}

我试过这个来抓住PolyLang当前的语言,但没有效果:

function language_switch() {
    if(pll_current_language=='en') {
        add_filter( 'woocommerce_product_description_heading', 'switch_product_description_heading' );
        function switch_product_description_heading() {
            return 'Attributes';
        }
    } elseif (pll_current_language=='th') {
        add_filter( 'woocommerce_product_description_heading', 'switch_product_description_heading' );
        function switch_product_description_heading() {
            return 'คุณลักษณะ';
        }
    }
}

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

pll_current_languagefunction所以你应该称之为

if(pll_current_language() =='en') {