Php 为Woocommerce 3中的产品设置最小默认权重
我试图在functions.php文件中向WooCommerce添加一个默认的产品发货重量,但没有效果,我不确定我是否使用了正确的代码段或代码段中缺少的部分 这是我正在使用的Php 为Woocommerce 3中的产品设置最小默认权重,php,wordpress,woocommerce,attributes,product,Php,Wordpress,Woocommerce,Attributes,Product,我试图在functions.php文件中向WooCommerce添加一个默认的产品发货重量,但没有效果,我不确定我是否使用了正确的代码段或代码段中缺少的部分 这是我正在使用的 add_filter('woocommerce_product_get_weight', 'woocommerce_product_get_weight_filter'); function woocommerce_product_get_weight_filter($weight) { $default_weigh
add_filter('woocommerce_product_get_weight', 'woocommerce_product_get_weight_filter');
function woocommerce_product_get_weight_filter($weight) {
$default_weight = 0.1;
if ((!is_numeric($weight)) || ($weight <= 0.001)) {
return $default_weight;
}
return $weight;
}
add_filter('woocommerce_product_get_weight','woocommerce_product_get_weight_filter');
函数商业\产品\获取\重量\过滤器($weight){
$default_weight=0.1;
如果((!is_numeric($weight))|($weight尝试使用empty()
和产品变体挂钩:
add_filter('woocommerce_product_variation_get_weight', 'woocommerce_product_get_weight_filter', 10, 2 );
add_filter('woocommerce_product_get_weight', 'woocommerce_product_get_weight_filter', 10, 2 );
function woocommerce_product_get_weight_filter( $weight, $product ) {
if ( empty($weight) || $weight <= 0.001 ) {
return 0.1;
}
return $weight;
}
add_filter('woocommerce_product_variation_get_weight','woocommerce_product_get_weight_filter',10,2);
添加过滤器(“woocommerce\u product\u get\u weight”,“woocommerce\u product\u get\u weight\u filter”,10,2);
函数:商业\产品\获取\重量\过滤器($weight,$product){
如果(空($weight)| |$weight可以,那么重量是否应该显示在shipping选项卡的edit product(编辑产品)页面中?@cubaton3否默认重量不显示在后端产品编辑页面中,因为这些复合挂钩仅适用于“查看”上下文,而不适用于“编辑”上下文(后端产品编辑页面在所有WC\u product
方法上使用“编辑”上下文)