I’m using the following PHP code in WooCommerce to hide product details on single product pages from customers, as the numbers are only for shipment calculations and aren’t accurate measurements for the products:
// hide weight etc from additional information
add_filter( 'woocommerce_product_get_weight', 'hide_single_product_dimensions', 25, 2 );
add_filter( 'woocommerce_product_get_width', 'hide_single_product_dimensions', 25, 2 );
add_filter( 'woocommerce_product_get_height', 'hide_single_product_dimensions', 25, 2 );
add_filter( 'woocommerce_product_get_length', 'hide_single_product_dimensions', 25, 2 );
function hide_single_product_dimensions( $value, $product ){
// Only on single product pages
if( is_product() )
$value = '';
return $value;
}
The code works, but another dev recently told me that woocommerce_product_get_weight (and the other 3) are deprecated, and that I should replace them.
I looked at the WooCommerce Code Reference, specifically the class-wc-deprecated-filter-hooks.php. From what I could gather, ‘woocommerce_product_get_weight’ is the replacement of the deprecated ‘woocommerce_product_weight’. I can’t find anything on ‘woocommerce_product_get_weight’ itself being deprecated. I have extensively googled it as well, but as I am a beginner, I may have used incorrect search terms.
Does anyone know if this filter is or isn’t deprecated? (If so, with what was it replaced?)
TL;DR is ‘woocommerce_product_get_weight’ a deprecated filter hook?
Robin R. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.