Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. add_filter( 'woo_discount_rules_price_strikeout_after_discount_price', 'woo_discount_rules_price_strikeout_after_discount_price_method', 10, 2 );
  2.  
  3. function woo_discount_rules_price_strikeout_after_discount_price_method($item_price, $product){
  4. if ( ! ( is_shop() || is_product_category() || is_product_tag() ) ) return $item_price;
  5. if($product->is_type(array('variable', 'subscription_variation', 'variable-subscription'))){
  6. // Searching for the default variation
  7. $default_attributes = $product->get_default_attributes();
  8.  
  9. // Loop through available variations
  10. foreach($product->get_available_variations() as $variation){
  11. $found = true; // Initializing
  12. // Loop through variation attributes
  13. foreach( $variation['attributes'] as $key => $value ){
  14. $taxonomy = str_replace( 'attribute_', '', $key );
  15. // Searching for a matching variation as default
  16. if( isset($default_attributes[$taxonomy]) && $default_attributes[$taxonomy] != $value ){
  17. $found = false;
  18. break;
  19. }
  20. }
  21.  
  22. // When it's found we set it and we stop the main loop
  23. if( $found ) {
  24. $default_variaton = $variation;
  25. break;
  26. } // If not we continue
  27. else {
  28. continue;
  29. }
  30. }
  31.  
  32. if(isset($default_variaton)){
  33. if(isset($default_variaton['variation_id']) && !empty($default_variaton['variation_id'])){
  34. $product = wc_get_product($default_variaton['variation_id']);
  35.  
  36. global $flycart_woo_discount_rules;
  37. if(!empty($flycart_woo_discount_rules)){
  38. $discounted_price = $flycart_woo_discount_rules->pricingRules->getDiscountPriceOfProduct($product);
  39. if($discounted_price != null && $discounted_price != ''){
  40. $item_price = preg_replace('/<\/del> <ins>.*<\/ins>/', '</del><ins>'.wc_price($discounted_price).$product->get_price_suffix($discounted_price).'</ins>', $item_price);
  41. }
  42. }
  43.  
  44. }
  45. }
  46. }
  47. return $item_price;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement