Woocommerce - 从商店页面中删除可用的产品库存编号 [英] Woocommerce - Remove the available product inventory number from the shop page
问题描述
在显示我的电子商务商店中所有产品的商店页面上,其目前正在显示产品名称旁边的产品计数(广告资源)编号,如下所示:
我找到并尝试使用此代码:
add_filter('woocommerce_subcategory_count_html','woo_remove_category_products_count');
function woo_remove_category_products_count(){
return;
}
但它不工作,因为它删除' 通知单个产品页面,这不是我需要的。
然后我尝试使用CSS:
.count {
display:none!important;
}
但不起作用。
我真的希望有人有一个解决方案。
@ Update1:
尝试此程式码片段功能但在逻辑上它应该做的工作(参见下面的模板的提取)
: remove_action 'woocommerce_before_shop_loop','woocommerce_result_count',20);
或者:
add_action('init',function(){
/ pre>
remove_action('woocommerce_before_shop_loop','woocommerce_result_count',20);
}
首先找到该计数中涉及的函数:
woocommerce_result_count / code>
。
然后我找到相关的钩子:
是模板
archive-product.php
的摘录:<?php
/ **
* woocommerce_before_shop_loop hook。
*
* @hooked woocommerce_result_count - 20& ==== ==== ==== Here @@@!
* @hooked woocommerce_catalog_ordering - 30
* /
do_action('woocommerce_before_shop_loop');
? ;
@ update2:
最后尝试根据 这个旧主题(见结尾) ,覆盖商店页面上的原生功能:
add_action('init',function(){
if(is_shop()){
function woocommerce_result_count(){
return;
}
}
}
>
if(is_shop()){
function woocommerce_result_count(){
return;
}
}
@ update3: - 另一个工作解决方案(覆盖模板文件)
<
函数
woocommerce_result_count()
请参阅loop / result-count.php
WooCommerce模板,您可以在此源代码中看到:if(!function_exists('woocommerce_result_count')) {
/ **
*输出结果计数文本(显示x - x个x结果)。
*
* @subpackage Loop
* /
function woocommerce_result_count(){
wc_get_template('loop / result-count.php');
}
}
解决方案:
位于
loop / result-count.php
WooCommerce模板中,添加:|| is_shop()
到if
语句 ,这样:<?php
/ **
*结果计数
*
... / ...
* @version 2.0.0
* /
if(!defined('ABSPATH')) {
exit; //如果直接访问则退出
}
global $ wp_query;
// @@@这里我们避免在商店页面上< ==== ==== ==== ==== ADDING|| is_shop()...
if(!woocommerce_products_will_display()|| is_shop())
return;
/ *
... / ...
* /
b $ b这次有效...
On the shop page that displays all the products in my e-commerce store, it's currently displaying the product count (inventory) number beside the name of the product as so:
I found and tried to use this code:
add_filter( 'woocommerce_subcategory_count_html', 'woo_remove_category_products_count' ); function woo_remove_category_products_count() { return; }
But it doesn't work because it removes the 'only 5 left in stock' notice on the individual product page and thats not what I need.
Then I have tried to use CSS:
.count { display: none !important; }
But doesn't work either.
I really hope someone has a solution for this. All suggestions very welcome and thanks for your efforts in advance!
解决方案@Update1:
Try this snippet code function (without guaranty, because untested), but logically it should do the job (see the extract of the template below):
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
Or alternatively:
add_action('init', function(){ remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); }
First find the function involved in that count:
woocommerce_result_count()
.Then I have Find the related hook:
Here is the extract of the template
archive-product.php
that shows the hook:<?php /** * woocommerce_before_shop_loop hook. * * @hooked woocommerce_result_count - 20 <==== ==== ==== ==== Here @@@ ! * @hooked woocommerce_catalog_ordering - 30 */ do_action( 'woocommerce_before_shop_loop' ); ?>
@update2: — This is working too (see update3: the alternative)
Last try based on this old thread (see at the end), overriding the native function on shop page:
add_action('init', function(){ if(is_shop()){ function woocommerce_result_count(){ return; } } }
Or alternatively:
if(is_shop()){ function woocommerce_result_count(){ return; } }
@update3: -- The other working solution (overriding template file)
The function
woocommerce_result_count()
refer toloop/result-count.php
WooCommerce template, as you can see in this source extract:if ( ! function_exists( 'woocommerce_result_count' ) ) { /** * Output the result count text (Showing x - x of x results). * * @subpackage Loop */ function woocommerce_result_count() { wc_get_template( 'loop/result-count.php' ); } }
The solution:
is in:
loop/result-count.php
WooCommerce template, adding:|| is_shop()
to theif
statement (on line 27), this way:<?php /** * Result Count * ... / ... * @version 2.0.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } global $wp_query; // @@@ Here we avoid count on shop page <==== ==== ==== ==== ADDING " || is_shop() "… if ( ! woocommerce_products_will_display() || is_shop() ) return; /* ... / ... */
That works this time…
Reference: Overriding Templates via a Theme (+Template Structure)
这篇关于Woocommerce - 从商店页面中删除可用的产品库存编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!