0
我正在與woocommerce集成的wordpress網站上工作。作爲標題的Woocommerce屬性
現在我想重寫項目的標題與同一項目的自定義屬性的值(在產品檔案頁和單產品頁)。
我搞亂了functions.php,但沒有任何工作適合我。
任何woocommerce/.php專家在這裏?提前致謝!
我正在與woocommerce集成的wordpress網站上工作。作爲標題的Woocommerce屬性
現在我想重寫項目的標題與同一項目的自定義屬性的值(在產品檔案頁和單產品頁)。
我搞亂了functions.php,但沒有任何工作適合我。
任何woocommerce/.php專家在這裏?提前致謝!
您需要使用the_title
過濾器以及in_the_loop
,is_shop
和is_product
有條件的如下所示。添加以下代碼您的主題的功能.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;
}
或者'woocommerce_product_title'是一個只能在產品上運行的過濾器。 – helgatheviking
@helgatheviking,我同意。但根據我的發現,它不適用於產品歸檔和單個產品頁面。它在購物車和結賬頁面上工作。 –
是的,它確實在我的網頁上工作,你能給我一個建議如何操縱過濾器@helgatheviking? –