Created
January 2, 2018 20:26
-
-
Save EricBusch/bbb2c72fcd037f1b9738e83c9de94753 to your computer and use it in GitHub Desktop.
Hide a product's price from display on single Product pages if a product contains a cached Comparison Set that meets the minimum number of results requirement. [datafeedr][dfrcs][woocommerce]
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 | |
/** | |
* Hide a product's price from display on single Product pages | |
* if a product contains a cached Comparison Set that meets the minimum number of | |
* results requirement. | |
* | |
* @param string $price HTML containing product price markup. | |
* @param WC_Product $product | |
* | |
* @return string Price | |
*/ | |
function mycode_hide_price_if_product_has_compset( $price, $product ) { | |
if ( ! is_product() ) { | |
return $price; | |
} | |
$source = dfrcs_wc_get_source_of_product(); | |
$source['context'] = 'wc_single_product_page'; | |
$compset = new Dfrcs( $source ); | |
// If compset is not cached, return default $price. | |
if ( ! $compset->cached ) { | |
return $price; | |
} | |
// If compset is not being displayed because of min product requirement, return default $price. | |
if ( ! $compset->meets_min_num_product_requirement() ) { | |
return $price; | |
} | |
$price = ''; | |
return $price; | |
} | |
add_filter( 'woocommerce_get_price_html', 'mycode_hide_price_if_product_has_compset', 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment