在 Woocommerce 商店页面上隐藏价格
Hiding prices on the Woocommerce shop pages
我正在使用带有 WooCommerce 插件的 WordPress,我想在商店页面上隐藏价格(例如 $20 - $50)。我曾尝试对其进行研究,但没有发现与此问题相关的太多信息。
我只想隐藏商店页面上的价格,而不是单个产品页面上的价格。
我们将不胜感激。
您可以使用这个简单的挂钩函数,它将所有产品价格从 Woocommerce 存档页面中删除,如商店、产品类别存档和产品标签存档页面:
add_filter( 'woocommerce_after_shop_loop_item_title', 'remove_woocommerce_loop_price', 2 );
function remove_woocommerce_loop_price() {
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
代码进入您的活动子主题(或主题)的 function.php 文件。 已测试并有效。
如果您只想定位商店页面,则必须这样做:
add_filter( 'woocommerce_after_shop_loop_item_title', 'remove_woocommerce_loop_price', 2 );
function remove_woocommerce_loop_price() {
if( ! is_shop() ) return; // only on shop pages
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
已更新:您可能还想将添加到购物车按钮替换为商店和存档页面中产品的链接按钮
// Replace add to cart button by a linked button to the product in Shop and archives pages
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product ) {
// Not needed for variable products
if( $product->is_type( 'variable' ) ) return $button;
// Button text here
$button_text = __( "View product", "woocommerce" );
return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
}
我正在使用带有 WooCommerce 插件的 WordPress,我想在商店页面上隐藏价格(例如 $20 - $50)。我曾尝试对其进行研究,但没有发现与此问题相关的太多信息。
我只想隐藏商店页面上的价格,而不是单个产品页面上的价格。
我们将不胜感激。
您可以使用这个简单的挂钩函数,它将所有产品价格从 Woocommerce 存档页面中删除,如商店、产品类别存档和产品标签存档页面:
add_filter( 'woocommerce_after_shop_loop_item_title', 'remove_woocommerce_loop_price', 2 );
function remove_woocommerce_loop_price() {
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
代码进入您的活动子主题(或主题)的 function.php 文件。 已测试并有效。
如果您只想定位商店页面,则必须这样做:
add_filter( 'woocommerce_after_shop_loop_item_title', 'remove_woocommerce_loop_price', 2 );
function remove_woocommerce_loop_price() {
if( ! is_shop() ) return; // only on shop pages
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
已更新:您可能还想将添加到购物车按钮替换为商店和存档页面中产品的链接按钮
// Replace add to cart button by a linked button to the product in Shop and archives pages
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product ) {
// Not needed for variable products
if( $product->is_type( 'variable' ) ) return $button;
// Button text here
$button_text = __( "View product", "woocommerce" );
return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
}