有人知道如何将产品尺寸隐藏在单个产品页面的附加选项卡中,但仍然显示权重值吗?
我搜索并看到这个过滤器,但它隐藏重量和尺寸。
add_filter( 'woocommerce_product_get_dimensions', '__return_false' );发布于 2018-09-06 08:52:55
只隐藏尺寸(而不是权重),有2方法使其工作。
1)使用钩子(此处是复合过滤器钩子):
查看在单个产品中显示维度的模板,您可以看到以下一行:
<?php if ( $display_dimensions && $product->has_dimensions() ) : ?>然后,如果您查看方法,您将看到这一行(其中$this是WC_Product对象实例)
return ( $this->get_length() || $this->get_height() || $this->get_width() ) && ! $this->get_virtual();因此,当长度、高度和with为空(或false)时,该方法返回false…
以下使用组合钩子的代码将仅在单个产品页中将维度隐藏在“附加信息”选项卡中:
add_filter( 'woocommerce_product_get_width', 'hide_single_product_dimentions', 25, 2 );
add_filter( 'woocommerce_product_get_height', 'hide_single_product_dimentions', 25, 2 );
add_filter( 'woocommerce_product_get_length', 'hide_single_product_dimentions', 25, 2 );
function hide_single_product_dimentions( $value, $product ){
// Only on single product pages
if( is_product() )
$value = '';
return $value;
} 代码在您的活动子主题(或活动主题)的function.php文件中。测试和工作。
用于隐藏权重(仅为获取信息),请使用以下复合钩子代码: add_filter(‘woocommerce_ product _get_get’,‘隐藏_单产品_get’,25,2 );函数hide_single_product_weight( $value,$product ){ /仅在单个产品页面上返回$value;}
2)通过活动主题覆盖Woocommerce模板:
第一读:通过主题覆盖Woocommerce模板。
它解释了如何在编辑模板之前将模板复制到主题中。
这里的相关模板是single-product/product-attributes.php。
您必须从模板代码中删除这个块(从第33行到第38行):
<?php if ( $display_dimensions && $product->has_dimensions() ) : ?>
<tr>
<th><?php _e( 'Dimensions', 'woocommerce' ) ?></th>
<td class="product_dimensions"><?php echo esc_html( wc_format_dimensions( $product->get_dimensions( false ) ) ); ?></td>
</tr>
<?php endif; ?>发布于 2018-09-06 09:21:03
如果其他一切都失败了,还可以使用css属性display:none。
https://stackoverflow.com/questions/52199913
复制相似问题