WCML_Dynamic_Pricing

Class WCML_Dynamic_Pricing.

Defined (1)

The class is defined in the following location(s).

/compatibility/class-wcml-dynamic-pricing.php  
  1. class WCML_Dynamic_Pricing { 
  2.  
  3. /** 
  4. * @var SitePress 
  5. */ 
  6. public $sitepress; 
  7.  
  8. /** 
  9. * WCML_Dynamic_Pricing constructor. 
  10. * @param $sitepress 
  11. */ 
  12. function __construct( &$sitepress ) { 
  13. if ( ! is_admin() ) { 
  14. $this->sitepress = $sitepress; 
  15. add_filter( 'wc_dynamic_pricing_load_modules', array( $this, 'filter_price' ) ); 
  16. add_filter( 'woocommerce_dynamic_pricing_is_applied_to', array( $this, 'woocommerce_dynamic_pricing_is_applied_to' ), 10, 5 ); 
  17. add_filter( 'woocommerce_dynamic_pricing_get_rule_amount', array( $this, 'woocommerce_dynamic_pricing_get_rule_amount' ), 10, 2 ); 
  18. add_filter( 'dynamic_pricing_product_rules', array( $this, 'dynamic_pricing_product_rules' ) ); 
  19. add_filter( 'wcml_calculate_totals_exception', array( $this, 'calculate_totals_exception' ) ); 
  20.  
  21. /** 
  22. * @param $modules 
  23. * @return mixed 
  24. */ 
  25. function filter_price( $modules ) { 
  26.  
  27. foreach ( $modules as $mod_key => $module ) { 
  28. if ( isset( $module->available_rulesets ) ) { 
  29. $available_rulesets = $module->available_rulesets; 
  30. foreach ( $available_rulesets as $rule_key => $available_ruleset ) { 
  31. $rules = $available_ruleset['rules']; 
  32. if ( $rules ) { 
  33. foreach ( $rules as $r_key => $rule ) { 
  34. if ( 'fixed_product' === $rule['type'] ) { 
  35. $rules[ $r_key ]['amount'] = apply_filters( 'wcml_raw_price_amount', $rule['amount'] ); 
  36. $modules[ $mod_key ]->available_rulesets[ $rule_key ]['rules'] = $rules; 
  37.  
  38. return $modules; 
  39.  
  40.  
  41. /** 
  42. * @param $process_discounts 
  43. * @param $_product 
  44. * @param $module_id 
  45. * @param $obj 
  46. * @param $cat_id 
  47. * @return bool|WP_Error 
  48. */ 
  49. function woocommerce_dynamic_pricing_is_applied_to( $process_discounts, $_product, $module_id, $obj, $cat_id ) { 
  50. if ( $cat_id && isset( $obj->available_rulesets ) && count( $obj->available_rulesets ) > 0 ) { 
  51. $cat_id = apply_filters( 'translate_object_id', $cat_id, 'product_cat', true, $this->sitepress->get_current_language() ); 
  52. $process_discounts = is_object_in_term( WooCommerce_Functions_Wrapper::get_product_id( $_product ), 'product_cat', $cat_id ); 
  53.  
  54. return $process_discounts; 
  55.  
  56.  
  57. /** 
  58. * @param $amount 
  59. * @param $rule 
  60. * @return mixed|void 
  61. */ 
  62. function woocommerce_dynamic_pricing_get_rule_amount( $amount, $rule ) { 
  63.  
  64. if ( 'price_discount' === $rule['type'] || 'fixed_price' === $rule['type'] ) { 
  65. $amount = apply_filters( 'wcml_raw_price_amount', $amount ); 
  66.  
  67. return $amount; 
  68.  
  69.  
  70. /** 
  71. * @param $rules 
  72. * @return array 
  73. */ 
  74. function dynamic_pricing_product_rules( $rules ) { 
  75. if ( is_array( $rules ) ) { 
  76. foreach ( $rules as $r_key => $rule ) { 
  77. foreach ( $rule['rules'] as $key => $product_rule ) { 
  78. if ( 'price_discount' === $product_rule['type'] || 'fixed_price' === $product_rule['type'] ) { 
  79. $rules[ $r_key ]['rules'][ $key ]['amount'] = apply_filters( 'wcml_raw_price_amount', $product_rule['amount'] ); 
  80. return $rules; 
  81.  
  82. /** 
  83. * @return bool 
  84. */ 
  85. function calculate_totals_exception() { 
  86. return false;