Last active
July 14, 2019 00:46
-
-
Save iconicwp/ddb467f95dedf250d635bbf196f955bd to your computer and use it in GitHub Desktop.
Change variation price range when using Show Single Variations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change variation price to parent. | |
* | |
* Implement this: https://iconicwp.com/blog/change-price-range-variable-products-woocommerce/ | |
* When using this plugin: https://iconicwp.com/products/woocommerce-show-single-variations/ | |
* | |
* @param float $price | |
* @param obj $product | |
* | |
* @return str | |
*/ | |
function iconic_variation_price_html( $price, $product ) { | |
if( ! $product->is_type( 'variation' ) ) { | |
return $price; | |
} | |
if( is_product() || is_cart() || is_checkout() ) { | |
return $price; | |
} | |
$parent = wc_get_product( $product->get_parent_id() ); | |
return $parent->get_price_html(); | |
} | |
add_filter( 'woocommerce_get_price_html', 'iconic_variation_price_html', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment