簡體   English   中英

在簡短描述字段中更改產品狀態 Woocommerce

[英]Change product status Woocommerce in short description field

我將產品狀態和其他信息放在 wp all import 的簡短描述字段中,用於所有產品,如下所示:

URL: <a href="https://www.msi.com/Graphics-card/GeForce-GTX-1650-GAMING-4G/Specification" target="_blank" rel="noopener noreferrer">Производител линк</a>
 <i class="fa fa-check" aria-hidden="true"></i> Наличен <i class="fa fa-truck" aria-hidden="true"></i> Доставка 1-3 дни

可用

如果產品類別是視頻卡,我希望將產品狀態和圖標更改為“調用”,而不是“可用”,如下所示:

URL: <a href="https://www.msi.com/Graphics-card/GeForce-GTX-1650-GAMING-4G/Specification" target="_blank" rel="noopener noreferrer">Производител линк</a>
 <i class="fa fa-volume-control-phone" aria-hidden="true"></i> Обадете се <i class="fa fa-truck" aria-hidden="true"></i> Доставка 1-3 дни

稱呼

在 wp all import 中或在我的活動子主題的 function.php 文件中使用自定義 function 有什么方法可以做到這一點?

您可以使用以下代碼:

<?php
add_filter( 'woocommerce_short_description', 'ywp_custom_single_excerpt' );
function ywp_custom_single_excerpt( $description ) {
    global $product;

    $categories = array( 'videocards' ); // You can add more categories

    if( has_term( $categories, 'product_cat', $product ) ) {
        return str_replace( '<i class="fa fa-check" aria-hidden="true"></i> Наличен ', '<i class="fa fa-volume-control-phone" aria-hidden="true"></i> Обадете се ', $description );
    }

    return $description;
}

代碼在您的活動主題/子主題的functions.php文件中。 測試和工作。

上面的代碼對我不起作用,所以我不得不修改它,這是一個工作代碼。 感謝 Hamid Reza Yazdani 的指導。

function magic_custom_text( $post_excerpt ) {   
    if ( is_product() && has_term( 'VIDEO CARD', 'product_cat' ) ) {
      return str_replace( '<i class="fa fa-check" aria-hidden="true"></i> Наличен ', '<i class="fa fa-volume-control-phone" aria-hidden="true"></i> Обадете се ', $post_excerpt );
    } else {
        return $post_excerpt;
    }
}
add_filter('woocommerce_short_description', 'magic_custom_text', 10, 1);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM