Skip to content

Instantly share code, notes, and snippets.

@Frique
Created April 18, 2021 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frique/3be3b55c103df1b18dcefc290356c90d to your computer and use it in GitHub Desktop.
Save Frique/3be3b55c103df1b18dcefc290356c90d to your computer and use it in GitHub Desktop.
WCSSM: Force the native sale-price overwrite
// Force the native sale-price overwrite
add_filter( 'get_post_metadata', 'wcssm_markus_filter_sale_price_meta', 11, 4 );
function wcssm_markus_filter_sale_price_meta( $value, $object_id, $meta_key, $single ) {
if ( $meta_key === '_sale_price' ) {
remove_filter( 'get_post_metadata', 'wcssm_markus_filter_sale_price_meta', 11, 4 );
if ( $sale = WCSSM::get_applicable_sale( $object_id ) ) {
$value = $sale['price'];
}
add_filter( 'get_post_metadata', 'wcssm_markus_filter_sale_price_meta', 11, 4 );
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment