How to exclude a specific woocommerce product attribute value in function?
-
I have an intermediate level php question as it relates to tweaking woocommerce.
Two parts: what I did and what I want to do. What I did. We wanted the price display to be other than the spread of [min-price – max-price] and have it say [“Starting at -” min-price]. This we accomplished with the following.:
` add_filter( ‘woocommerce_variable_sale_price_html’, ‘hide_variable_max_price’, PHP_INT_MAX, 2 );
add_filter( ‘woocommerce_variable_price_html’, ‘hide_variable_max_price’, PHP_INT_MAX, 2 );
function hide_variable_max_price( $price, $_product ) {
$min_price_regular = $_product->get_variation_regular_price( ‘min’, true );
$min_price_sale = $_product->get_variation_sale_price( ‘min’, true );
return ( $min_price_sale == $min_price_regular ) ?
‘Starting at ‘. wc_price( $min_price_regular ) :
‘<del>’. wc_price( $min_price_regular ) . ‘</del>’ . ‘<ins>’ . wc_price( $min_price_sale ) . ‘</ins>’;
}`
What we want to do: many, but not all of our products are sold in pairs and singly for which we have product attribute of ‘Pair or Single?” with the two values of ‘pair’ and ‘single’. What is happening now with the min-price is grabbing the ‘single’ value since this is typically half of the lowest price pair. What we want is for the min-price for the lowest price pair. So my question is: can I edit the above code to exclude attribute value ‘single’ from the resulting min-price? But also account for some products that do not use this attribute?
- The topic ‘How to exclude a specific woocommerce product attribute value in function?’ is closed to new replies.