i have a Woocommerce e-shop and i have added a custom field for the wholesale prices. How i can get the min_price and max_price from the custome field in variable products?
i have this php script added to functions.php
add_filter( 'woocommerce_get_price_html', 'empty_and_zero_price_html', 20, 2 );
function empty_and_zero_price_html( $price, $product ) {
global $ask_for_price;
global $whuser;
if($product->is_type('variable') and !is_admin()) {
$prices = $product->get_variation_prices( true );
if($whuser) {
$myprice = (float) get_post_meta( $variation_id, '_pricew', true );
} else {
$myprice = $prices['price'];
}
if ( empty( $myprice) or $myprice==0 ) {
return $ask_for_price; // <=== HERE below for empty price
} else {
$min_price = current( $myprice );
$max_price = end( $myprice );
if ( $min_price === $max_price && 0 == $min_price ) {
return $ask_for_price; // <=== HERE for zero price
}
elseif ( $min_price !== $max_price && 0 == $min_price ) {
return wc_price( $max_price );
}
}
}
else if($product->is_type('simple') and !is_admin()) {
if ( '' === $product->get_price() || 0 == $product->get_price() ) {
return $ask_for_price; // <=== HERE for empty and zero prices
}
}
return $price;
}
i have replaced the $prices[‘price’] with $myprice (wholesale price) but it’s returning zero (0).
what i’m doing wrong?