Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'woo_discount_rules_price_strikeout_after_discount_price', 'woo_discount_rules_price_strikeout_after_discount_price_method', 10, 2 );
- function woo_discount_rules_price_strikeout_after_discount_price_method($item_price, $product){
- if ( ! ( is_shop() || is_product_category() || is_product_tag() ) ) return $item_price;
- if($product->is_type(array('variable', 'subscription_variation', 'variable-subscription'))){
- // Searching for the default variation
- $default_attributes = $product->get_default_attributes();
- // Loop through available variations
- foreach($product->get_available_variations() as $variation){
- $found = true; // Initializing
- // Loop through variation attributes
- foreach( $variation['attributes'] as $key => $value ){
- $taxonomy = str_replace( 'attribute_', '', $key );
- // Searching for a matching variation as default
- if( isset($default_attributes[$taxonomy]) && $default_attributes[$taxonomy] != $value ){
- $found = false;
- break;
- }
- }
- // When it's found we set it and we stop the main loop
- if( $found ) {
- $default_variaton = $variation;
- break;
- } // If not we continue
- else {
- continue;
- }
- }
- if(isset($default_variaton)){
- if(isset($default_variaton['variation_id']) && !empty($default_variaton['variation_id'])){
- $product = wc_get_product($default_variaton['variation_id']);
- global $flycart_woo_discount_rules;
- if(!empty($flycart_woo_discount_rules)){
- $discounted_price = $flycart_woo_discount_rules->pricingRules->getDiscountPriceOfProduct($product);
- if($discounted_price != null && $discounted_price != ''){
- $item_price = preg_replace('/<\/del> <ins>.*<\/ins>/', '</del><ins>'.wc_price($discounted_price).$product->get_price_suffix($discounted_price).'</ins>', $item_price);
- }
- }
- }
- }
- }
- return $item_price;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement