如何在商店頁面 WooCommerce 中隱藏受保護產品的價格?
uj5u.com熱心網友回復:
要隱藏受保護產品的價格,您可以添加一個過濾器以顯示價格 html 并檢查產品是否受保護,檢查是否設定了密碼,如果設定了則不回傳值。
add_filter( 'woocommerce_get_price_html', 'hide_protected_product_price', 10, 2 );
function hide_protected_product_price( $price, $product ) {
if ( ! empty( $product->get_post_password() ) && ! is_single() ) {
return '';
}
return $price;
}
“受保護:”由 WordPress 添加,而不是 WooCommerce。要將“Protected:”替換為“Reserved:”,您需要添加 protected_title_format 過濾器。為確保您只為產品執行此操作,請首先檢查 post_type
function jt_replace_product_protected_text( $prepend ) {
global $post;
if ( $post->post_type == 'product' ) {
return __( 'Reserved: %s' );
}
return $prepend;
}
add_filter( 'protected_title_format', 'jt_replace_product_protected_text' );
uj5u.com熱心網友回復:
有2個選項:
1-如果您希望沒有任何產品有價格,您可以在目錄模式下轉換在線商店。要在目錄模式下設定,您必須安裝一個插件,例如我使用 YITH WOOCOMMERCE CATALOG MODE。
2-如果它只是一個產品,只是你在 woocomerce/products 中配置產品時沒有給出價格。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/468966.html