Osc*_*son 3 php wordpress product woocommerce price
我正在使用带有 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 );
}
Run Code Online (Sandbox Code Playgroud)
代码位于活动子主题(或主题)的 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 );
}
Run Code Online (Sandbox Code Playgroud)
更新:您可能还想用商店和档案页面中产品的链接按钮替换“添加到购物车”按钮
// 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>';
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4370 次 |
| 最近记录: |