第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

更改 WooCommerce 產(chǎn)品描述選項(xiàng)卡按鈕和標(biāo)題

更改 WooCommerce 產(chǎn)品描述選項(xiàng)卡按鈕和標(biāo)題

PHP
九州編程 2023-08-19 16:17:41
當(dāng)頁(yè)面的主體類(lèi)為“parent-product_cat-vinyl”時(shí),我想將 WooCommerce 產(chǎn)品描述選項(xiàng)卡按鈕和標(biāo)題“描述”更改為“Tracklist”。到目前為止,這是我的代碼:<?phpif ( is_singular() ) {   $classes = get_body_class();   if (in_array('parent-product_cat-vinyl',$classes)) {       add_filter( 'woocommerce_product_description_tab_title','ps_rename_description_product_tab_label');       function ps_rename_description_product_tab_label() {           return 'Tracklist';       }   }}但這似乎不起作用。
查看完整描述

1 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊

您可以使用以下復(fù)合過(guò)濾器掛鉤($tab_key在您的情況下是description):

  • woocommerce_product_{$tab_key}_tab_title

  • woocommerce_product_{$tab_key}_heading

可以通過(guò)兩種方式完成:

有條件地使用定義的主體類(lèi):

add_filter( 'woocommerce_product_description_tab_title', 'change_product_description_tab_text' );

add_filter( 'woocommerce_product_description_heading', 'change_product_description_tab_text' );

function change_product_description_tab_text( $title ) {

    global $product;


    if( in_array( 'parent-product_cat-vinyl', get_body_class() ) ) {

        return __('Tracklist', 'woocommerce');

    }

    return $title;

}

或者有條件地針對(duì)產(chǎn)品類(lèi)別(包括父產(chǎn)品類(lèi)別):


// Custom conditional function that handle parent product categories too

function has_product_categories( $categories, $product_id = 0 ) {

    $parent_term_ids = $categories_ids = array(); // Initializing

    $taxonomy        = 'product_cat';

    $product_id      = $product_id == 0 ? get_the_id() : $product_id;


    if( is_string( $categories ) ) {

        $categories = (array) $categories; // Convert string to array

    }


    // Convert categories term names and slugs to categories term ids

    foreach ( $categories as $category ){

        $result = (array) term_exists( $category, $taxonomy );

        if ( ! empty( $result ) ) {

            $categories_ids[] = reset($result);

        }

    }


    // Loop through the current product category terms to get only parent main category term

    foreach( get_the_terms( $product_id, $taxonomy ) as $term ){

        if( $term->parent > 0 ){

            $parent_term_ids[] = $term->parent; // Set the parent product category

            $parent_term_ids[] = $term->term_id; // (and the child)

        } else {

            $parent_term_ids[] = $term->term_id; // It is the Main category term and we set it.

        }

    }

    return array_intersect( $categories_ids, array_unique($parent_term_ids) ) ? true : false;

}


add_filter( 'woocommerce_product_description_tab_title', 'change_product_description_tab_text' );

add_filter( 'woocommerce_product_description_heading', 'change_product_description_tab_text' );

function change_product_description_tab_text( $title ) {

    global $product;

    

    // Here set in the array the targeted product categories

    $categories = array('Vinyl');


    if ( has_product_categories( $categories, $product->get_id() ) ) {

         return __('Tracklist', 'woocommerce');

    }

    return $title;

}

代碼位于活動(dòng)子主題(或活動(dòng)主題)的functions.php 文件中。經(jīng)過(guò)測(cè)試并有效。


查看完整回答
反對(duì) 回復(fù) 2023-08-19
  • 1 回答
  • 0 關(guān)注
  • 199 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)