WCML_Custom_Prices_UI

Created by OnTheGo Systems.

Defined (1)

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

/inc/template-classes/multi-currency/class-wcml-custom-prices-ui.php  
  1. class WCML_Custom_Prices_UI extends WPML_Templates_Factory { 
  2.  
  3. private $woocommerce_wpml; 
  4. private $product_id; 
  5. private $custom_prices; 
  6. private $is_variation; 
  7.  
  8.  
  9. function __construct( &$woocommerce_wpml, $product_id ) { 
  10. parent::__construct(); 
  11.  
  12. $this->woocommerce_wpml = $woocommerce_wpml; 
  13. $this->product_id = $product_id; 
  14. $this->is_variation = get_post_type( $product_id) == 'product_variation' ? true : false; 
  15. $this->custom_prices = get_post_custom( $product_id ); 
  16. $this->custom_prices_fields = apply_filters( 'wcml_custom_prices_fields', array( '_regular_price', '_sale_price' ), $product_id ); 
  17. $this->custom_prices_fields_labels = apply_filters( 'wcml_custom_prices_fields_labels', array( '_regular_price' => __( 'Regular Price', 'woocommerce-multilingual' ), '_sale_price' => __( 'Sale Price', 'woocommerce-multilingual' ) ), $product_id ); 
  18.  
  19. public function get_model() { 
  20. $model = array( 
  21. 'product_id' => $this->product_id,  
  22. 'currencies' => $this->get_currencies_info(),  
  23. 'checked_calc_auto' => !isset($this->custom_prices['_wcml_custom_prices_status']) || (isset($this->custom_prices['_wcml_custom_prices_status']) && $this->custom_prices['_wcml_custom_prices_status'][0] == 0)? 'checked="checked"' : '' ,  
  24. 'checked_calc_manually' => isset($this->custom_prices['_wcml_custom_prices_status']) && $this->custom_prices['_wcml_custom_prices_status'][0] == 1?'checked="checked"':'',  
  25. 'wc_currencies' => get_woocommerce_currencies(),  
  26. 'is_variation' => $this->is_variation,  
  27. 'html_id' => $this->is_variation ? '['.$this->product_id.']' : '',  
  28. 'strings' => apply_filters( 'wcml_custom_prices_strings', array( 
  29. 'not_set' => sprintf( __( 'Multi-currency is enabled but no secondary currencies have been set. %sAdd secondary currencies%s.',  
  30. 'woocommerce-multilingual' ), '<a href="' . admin_url('admin.php?page=wpml-wcml&tab=multi-currency') . '">', '</a>' ),  
  31. 'calc_auto' => __( 'Calculate prices in other currencies automatically', 'woocommerce-multilingual' ),  
  32. 'see_prices' => __( 'Click to see the prices in the other currencies as they are currently shown on the front end.', 'woocommerce-multilingual' ),  
  33. 'show' => __( 'Show', 'woocommerce-multilingual' ),  
  34. 'hide' => __( 'Hide', 'woocommerce-multilingual' ),  
  35. 'set_manually' => __( 'Set prices in other currencies manually', 'woocommerce-multilingual' ),  
  36. 'enter_prices' => __( 'Enter prices in other currencies', 'woocommerce-multilingual' ),  
  37. 'hide_prices' => __( 'Hide prices in other currencies', 'woocommerce-multilingual' ),  
  38. 'det_auto' => __( 'Determined automatically based on exchange rate', 'woocommerce-multilingual' ),  
  39. '_regular_price' => __( 'Regular Price', 'woocommerce-multilingual' ),  
  40. '_sale_price' => __( 'Sale Price', 'woocommerce-multilingual' ),  
  41. 'schedule' => __( 'Schedule', 'woocommerce-multilingual' ),  
  42. 'same_as_def' => __( 'Same as default currency', 'woocommerce-multilingual' ),  
  43. 'set_dates' => __( 'Set dates', 'woocommerce-multilingual' ),  
  44. 'collapse' => __( 'Collapse', 'woocommerce-multilingual' ),  
  45. 'from' => __( 'From…', 'woocommerce-multilingual' ),  
  46. 'to' => __( 'To…', 'woocommerce-multilingual' ),  
  47. 'enter_price' => __( 'Please enter in a value less than the regular price', 'woocommerce-multilingual' ) ),  
  48. $this->product_id 
  49. ); 
  50.  
  51. return $model; 
  52.  
  53.  
  54. public function get_currencies_info( ) { 
  55.  
  56. $currencies = $this->woocommerce_wpml->multi_currency->get_currencies(); 
  57. $wc_currencies = get_woocommerce_currencies(); 
  58.  
  59. foreach( $currencies as $key => $currency ) { 
  60.  
  61. $currencies[ $key ][ 'currency_code' ] = $key; 
  62.  
  63. foreach( $this->custom_prices_fields as $price_field ) { 
  64. $currencies[ $key ][ 'readonly_price' ][ $price_field ] = ''; 
  65. $currencies[ $key ][ 'custom_price' ][ $price_field ] = ''; 
  66.  
  67. if( $this->product_id ) { 
  68.  
  69. foreach( $this->custom_prices_fields as $price_field ) { 
  70. $currencies[ $key ][ 'readonly_price' ][ $price_field ] = get_post_meta( $this->product_id, $price_field, true ); 
  71. if( $currencies[ $key ][ 'readonly_price' ][ $price_field ] ) { 
  72. $currencies[ $key ][ 'readonly_price' ][ $price_field ] = $currencies[ $key ][ 'readonly_price' ][ $price_field ]*$currency['rate']; 
  73. $currencies[ $key ][ 'readonly_price' ][ $price_field ] = wc_format_localized_price( $currencies[ $key ][ 'readonly_price' ][ $price_field ] ); 
  74.  
  75.  
  76. if( isset( $this->custom_prices[ '_wcml_custom_prices_status' ] ) ) { 
  77.  
  78. foreach( $this->custom_prices_fields as $price_field ) { 
  79. if( isset( $this->custom_prices[ $price_field.'_'.$key ][ 0 ] ) ) { 
  80. $currencies[ $key ][ 'custom_price' ][ $price_field ] = wc_format_localized_price( $this->custom_prices[ $price_field.'_'.$key ][ 0 ] ); 
  81.  
  82.  
  83. $currencies[ $key ][ 'currency_format' ] = $wc_currencies[ $key ].' ( '.get_woocommerce_currency_symbol( $key ).' )'; 
  84. $currencies[ $key ][ 'currency_symbol' ] = get_woocommerce_currency_symbol( $key ); 
  85.  
  86. if( $this->is_variation ) { 
  87. $currencies[ $key ][ 'custom_id' ] = '['.$key.']['.$this->product_id.']'; 
  88. }else{ 
  89. $currencies[ $key ][ 'custom_id' ] = '['.$key.']'; 
  90.  
  91. $wc_input = array(); 
  92.  
  93. $wc_input['custom_attributes'] = array() ; 
  94. $wc_input['type_name'] = 'data_type'; 
  95. $wc_input['type_val'] = 'price'; 
  96.  
  97. foreach( $this->custom_prices_fields as $price_field ) { 
  98. ob_start(); 
  99. woocommerce_wp_text_input( 
  100. array( 
  101. 'id' => '_custom'.$price_field.'['.$key.']',  
  102. 'value'=> wc_format_localized_price( $currencies[ $key ][ 'custom_price' ][ $price_field ] ),  
  103. 'class' => 'wc_input_price wcml_input_price short wcml'.$price_field,  
  104. 'label' => $this->custom_prices_fields_labels[ $price_field ] . ' ('. $currencies[ $key ][ 'currency_symbol' ].')',  
  105. $wc_input['type_name'] => $wc_input['type_val'],  
  106. 'custom_attributes' => $wc_input['custom_attributes'] 
  107. ); 
  108. $currencies[ $key ][ 'custom_html' ][ $price_field ] = ob_get_contents(); 
  109. ob_end_clean(); 
  110.  
  111. $wc_input['custom_attributes'] = array( 'readonly' => 'readonly', 'rel'=> $currency['rate'] ) ; 
  112.  
  113. foreach( $this->custom_prices_fields as $price_field ) { 
  114. ob_start(); 
  115. woocommerce_wp_text_input( 
  116. array( 
  117. 'id' => '_readonly'.$price_field,  
  118. 'value'=> wc_format_localized_price( $currencies[ $key ][ 'readonly_price' ][ $price_field ] ),  
  119. 'class' => 'wc_input_price short',  
  120. 'label' => $this->custom_prices_fields_labels[ $price_field ] . ' ('. $currencies[ $key ][ 'currency_symbol' ] .')',  
  121. $wc_input['type_name'] => $wc_input['type_val'],  
  122. 'custom_attributes' => $wc_input['custom_attributes'] 
  123. ); 
  124. $currencies[ $key ][ 'readonly_html' ][ $price_field ] = ob_get_contents(); 
  125. ob_end_clean(); 
  126.  
  127. $currencies[ $key ][ 'schedule_auto_checked' ] = (!isset($this->custom_prices['_wcml_schedule_'.$key]) || (isset($this->custom_prices['_wcml_schedule_'.$key]) && $this->custom_prices['_wcml_schedule_'.$key][0] == 0))?'checked="checked"':' '; 
  128. $currencies[ $key ][ 'schedule_man_checked' ] = isset($this->custom_prices['_wcml_schedule_'.$key]) && $this->custom_prices['_wcml_schedule_'.$key][0] == 1?'checked="checked"':' '; 
  129.  
  130.  
  131. $currencies[ $key ][ 'sale_price_dates_from' ] = (isset($this->custom_prices['_sale_price_dates_from_'.$key]) && $this->custom_prices['_sale_price_dates_from_'.$key][0] != '') ? date_i18n( 'Y-m-d', $this->custom_prices['_sale_price_dates_from_'.$key][0] ) : ''; 
  132. $currencies[ $key ][ 'sale_price_dates_to' ] = (isset($this->custom_prices['_sale_price_dates_to_'.$key]) && $this->custom_prices['_sale_price_dates_to_'.$key][0] != '') ? date_i18n( 'Y-m-d', $this->custom_prices['_sale_price_dates_to_'.$key][0] ) : ''; 
  133.  
  134.  
  135. return $currencies; 
  136.  
  137.  
  138.  
  139. public function init_template_base_dir() { 
  140. $this->template_paths = array( 
  141. WCML_PLUGIN_PATH . '/templates/multi-currency/',  
  142. ); 
  143.  
  144. public function get_template() { 
  145. return 'custom-prices.twig'; 
  146.