[英]Only show price when is_archive woocommerce
在 woocommerce 中,我不想在產品存檔上顯示價格。 我使用代碼:
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
這工作正常。 但如果我正在展示產品,它會消除每個街區的價格。 我只想在存檔頁面上執行代碼。
我試過代碼:
if (is_archive()) {
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
這沒用。 我做了很多研究,發現了一些關於加載層次結構的文章。 這是有道理的。 在其他一些情況下,我使用了 `add_action('after_setup_theme', 'delete_price_test');'。 這為我的主題中的鈎子完成了工作。
function delete_price_test() {
if (is_archive()) {
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
add_action( 'after_setup_theme', 'delete_price_test');
我沒有讓我的代碼工作。 我嘗試了一切,搜索了論壇,谷歌搜索等等,但沒有解決方案。 有人可以幫我解決這個問題嗎?
克魯,弗蘭斯
請試試這個。
/** * Hide price everywhere ( exclude category page) */ function bml_not_hide_prices_on_all_categories( $price, $product ) { if ( is_product_category() ) { return $price; } return ''; // Empty string = no price! } add_filter( 'woocommerce_get_price_html', 'bml_not_hide_prices_on_all_categories', 10, 2 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.