我正在嘗試使用過濾器“the_content”在單個頁面(woocommerce,它的產品)中更改 Wordpress 帖子的 the_content,它作業得相當簡潔——只有在該帖子中沒有內容(沒有詳細描述的產品)我的主題沒有' 甚至不顯示內容容器,因此甚至從不呼叫 the_content。我無權訪問這些函式,我插入片段 - 我必須檢查空內容,我怎么能改變它(我可以嗎? ) 不更新資料庫中的帖子?
如果內容甚至包含一個字符,這就是有效的:
add_filter('the_content','produktbeschrieb',-1);
function produktbeschrieb($content) {
$kategorien = get_the_term_list( $post->ID, 'product_cat', '', ', ') ;
if ( is_singular() && in_the_loop() && is_main_query() ) {
if(str_contains($kategorien,'R&F Pigment Sticks')){
return $content."<p>R&F Pigment Sticks? sind ?lfarben, die so viel Wachs enthalten, dass die Farbe in St?bchenform gegossen werden kann. </p>";
}
else {
return $content;}
}
uj5u.com熱心網友回復:
該解決方案可能在一定程度上取決于您使用的主題。但我已經測驗了以下內容,它對我有用。我相信默認情況下,如果沒有描述,WooCommerce 不會添加描述選項卡,因此當它是具有空描述的產品時,您需要將其添加回來,然后通過使用設定描述為空時的值您已經撰寫的過濾器。
add_filter('the_content','produktbeschrieb',-1);
function produktbeschrieb($content) {
$kategorien = get_the_term_list( $post->ID, 'product_cat', '', ', ') ;
if ( is_singular() && in_the_loop() && is_main_query() ) {
if(str_contains($kategorien,'R&F Pigment Sticks')){
return $content."<p>R&F Pigment Sticks? sind ?lfarben, die so viel Wachs enthalten, dass die Farbe in St?bchenform gegossen werden kann. </p>";
}
else {
return $content;}
}
function woocommerce_empty_description_callback() {
global $product;
if( is_product() && empty( $product->get_description() ) ) {
echo apply_filters( 'the_content', '' );
}
}
function jt_woocommerce_default_product_tabs($tabs) {
if ( empty( $tabs['description'] ) ) {
$tabs['description'] = array(
'title' => __( 'Description', 'woocommerce' ),
'priority' => 10,
'callback' => 'woocommerce_empty_description_callback',
);
}
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'jt_woocommerce_default_product_tabs' );
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/466611.html
上一篇:WooCommerce/WordPress從鉤子中洗掉HTML屬性
下一篇:標題WooCommerce網關
