Skip to content

Instantly share code, notes, and snippets.

@iconicwp
Last active July 14, 2019 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iconicwp/ddb467f95dedf250d635bbf196f955bd to your computer and use it in GitHub Desktop.
Save iconicwp/ddb467f95dedf250d635bbf196f955bd to your computer and use it in GitHub Desktop.
Change variation price range when using Show Single Variations
<?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