WC_POS_Params

POS App parameters.

Defined (1)

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

/includes/class-wc-pos-params.php  
  1. class WC_POS_Params { 
  2.  
  3. /** 
  4. * Constructor 
  5. */ 
  6. public function __construct() { 
  7.  
  8. // this should only be init after woocommerce_init 
  9. global $wp_actions; 
  10. if( ! isset($wp_actions['woocommerce_init']) ) { 
  11. return; 
  12.  
  13. // common params 
  14. $this->accounting = $this->accounting(); 
  15. $this->ajaxurl = admin_url( 'admin-ajax.php', 'relative' ); 
  16. $this->customers = $this->customers(); 
  17. $this->debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; 
  18. $this->nonce = wp_create_nonce( WC_POS_PLUGIN_NAME ); 
  19. $this->rest_nonce = wp_create_nonce( 'wp_rest' ); 
  20. $this->wc_api = get_wcpos_api_url(''); 
  21. $this->emulateHTTP = get_option( 'woocommerce_pos_emulateHTTP' ) === '1'; 
  22. $this->idbVersion = WC_POS_Settings::get_idb_version(); 
  23.  
  24. // frontend params 
  25. if( is_pos() ) { 
  26. $this->auto_print = wc_pos_get_option( 'checkout', 'auto_print_receipt' ); 
  27. $this->denominations = WC_POS_i18n::currency_denominations(); 
  28. $this->discount_keys = wc_pos_get_option( 'general', 'discount_quick_keys' ); 
  29. $this->hotkeys = wc_pos_get_option( 'hotkeys', 'hotkeys' ); 
  30. $this->menu = $this->menu(); 
  31. $this->shipping = $this->shipping_labels(); 
  32. $this->store = array( 'name' => get_bloginfo( 'name' ) ); 
  33. $this->tabs = $this->product_tabs(); 
  34. $this->tax = $this->tax(); 
  35. $this->tax_classes = WC_POS_Tax::tax_classes(); 
  36. $this->tax_rates = WC_POS_Tax::tax_rates(); 
  37. $this->user = $this->user(); 
  38.  
  39. // admin params 
  40. if( is_admin() ) { 
  41. $this->search_customers_nonce = wp_create_nonce( 'search-customers' ); 
  42.  
  43.  
  44. /** 
  45. * Params payload for 
  46. * Converts class properties to array 
  47. * @return array 
  48. */ 
  49. public function payload() { 
  50. return apply_filters( 'woocommerce_pos_params', get_object_vars( $this ), $this ); 
  51.  
  52. /** 
  53. * Default quick tabs for products 
  54. * @return array 
  55. */ 
  56. private function product_tabs() { 
  57. return array( 
  58. 'all' => array( 
  59. /** translators: woocommerce */ 
  60. 'label' => __( 'All', 'woocommerce'),  
  61. 'active' => true 
  62. ),  
  63. 'featured' => array( 
  64. /** translators: woocommerce */ 
  65. 'label' => __( 'Featured', 'woocommerce'),  
  66. 'id' => 'featured:true' 
  67. ),  
  68. 'onsale' => array( 
  69. 'label' => _x( 'On Sale', 'Product tab: \'On Sale\' products', 'woocommerce-pos'),  
  70. 'id' => 'on_sale:true' 
  71. ),  
  72. ); 
  73.  
  74. /** 
  75. * Get the accounting format from user settings 
  76. * POS uses a plugin to format currency: http://josscrowcroft.github.io/accounting.js/ 
  77. * @return array $settings 
  78. */ 
  79. private function accounting() { 
  80. $decimal = get_option( 'woocommerce_price_decimal_sep' ); 
  81. $thousand = get_option( 'woocommerce_price_thousand_sep' ); 
  82. $precision = get_option( 'woocommerce_price_num_decimals' ); 
  83. return array( 
  84. 'currency' => array( 
  85. 'decimal' => $decimal,  
  86. 'format' => $this->currency_format(),  
  87. 'precision' => $precision,  
  88. 'symbol' => get_woocommerce_currency_symbol( get_woocommerce_currency() ),  
  89. 'thousand' => $thousand,  
  90. ),  
  91. 'number' => array( 
  92. 'decimal' => $decimal,  
  93. 'precision' => $precision,  
  94. 'thousand' => $thousand,  
  95. ); 
  96.  
  97. /** 
  98. * Get the currency format from user settings 
  99. * @return array $format 
  100. */ 
  101. private function currency_format() { 
  102. $currency_pos = get_option( 'woocommerce_currency_pos' ); 
  103.  
  104. if( $currency_pos == 'right' ) 
  105. return array('pos' => '%v%s', 'neg' => '- %v%s', 'zero' => '%v%s'); 
  106.  
  107. if( $currency_pos == 'left_space' ) 
  108. return array('pos' => '%s %v', 'neg' => '- %s %v', 'zero' => '%s %v'); 
  109.  
  110. if( $currency_pos == 'right_space' ) 
  111. return array('pos' => '%v %s', 'neg' => '- %v %s', 'zero' => '%v %s'); 
  112.  
  113. // default = left 
  114. return array('pos' => '%s%v', 'neg' => '- %s%v', 'zero' => '%s%v'); 
  115.  
  116. /** 
  117. * Get the default customer + guest 
  118. * @return object $customer 
  119. */ 
  120. private function customers() { 
  121.  
  122. $user_id = wc_pos_get_option( 'general', 'logged_in_user' ) ? 
  123. get_current_user_id() : 
  124. wc_pos_get_option( 'general', 'default_customer' ); 
  125.  
  126. if( $user_id ) { 
  127. $user = get_userdata($user_id); 
  128. $customers['default'] = array( 
  129. 'id' => $user->ID,  
  130. 'first_name' => esc_html($user->first_name),  
  131. 'last_name' => esc_html($user->last_name),  
  132. 'email' => esc_html($user->user_email),  
  133. 'username' => esc_html($user->user_login) 
  134. ); 
  135.  
  136. $customers['guest'] = array( 
  137. 'id' => 0,  
  138. /** translators: woocommerce */ 
  139. 'first_name' => __( 'Guest', 'woocommerce' ) 
  140. ); 
  141.  
  142. return $customers; 
  143.  
  144. /** 
  145. * Get the woocommerce shop settings 
  146. * @return array $settings 
  147. */ 
  148. private function tax() { 
  149. return array( 
  150. 'tax_label' => WC()->countries->tax_or_vat(),  
  151. 'calc_taxes' => get_option( 'woocommerce_calc_taxes' ),  
  152. 'prices_include_tax' => get_option( 'woocommerce_prices_include_tax' ),  
  153. 'tax_round_at_subtotal' => get_option( 'woocommerce_tax_round_at_subtotal' ),  
  154. 'tax_display_cart' => get_option( 'woocommerce_tax_display_cart' ),  
  155. 'tax_total_display' => get_option( 'woocommerce_tax_total_display' ),  
  156. ); 
  157.  
  158. /** 
  159. * User settings 
  160. * @return array $settings 
  161. */ 
  162. private function user() { 
  163. global $current_user; 
  164.  
  165. return array( 
  166. 'id' => $current_user->ID,  
  167. 'display_name' => $current_user->display_name 
  168. ); 
  169.  
  170. /** 
  171. * @return array 
  172. */ 
  173. static public function shipping_labels() { 
  174. $labels = array(); 
  175.  
  176. // WC < 3 can have empty method_id 
  177. if( version_compare( WC()->version, '3', '<' ) ) { 
  178. /** translators: woocommerce */ 
  179. $labels[''] = __('N/A', 'woocommerce'); 
  180.  
  181. $shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array(); 
  182.  
  183. foreach( $shipping_methods as $method ) { 
  184. // backwards compat: $method->get_method_title introduced in WC 2.6.0 
  185. $labels[$method->id] = method_exists($method, 'get_method_title') ? $method->get_method_title() : $method->get_title(); 
  186.  
  187. /** translators: woocommerce */ 
  188. $labels['other'] = __( 'Other', 'woocommerce' ); 
  189.  
  190. return $labels; 
  191.  
  192. /** 
  193. */ 
  194. private function menu() { 
  195.  
  196. return apply_filters( 'woocommerce_pos_menu', array( 
  197. array( 
  198. 'id' => 'pos',  
  199. 'label' => __( 'POS', 'woocommerce-pos' ),  
  200. 'href' => '#' 
  201. ),  
  202. array( 
  203. 'id' => 'products',  
  204. /** translators: woocommerce */ 
  205. 'label' => __( 'Products', 'woocommerce' ),  
  206. 'href' => admin_url('edit.php?post_type=product') 
  207. ),  
  208. array( 
  209. 'id' => 'orders',  
  210. /** translators: woocommerce */ 
  211. 'label' => __( 'Orders', 'woocommerce' ),  
  212. 'href' => admin_url('edit.php?post_type=shop_order') 
  213. ),  
  214. array( 
  215. 'id' => 'customers',  
  216. /** translators: woocommerce */ 
  217. 'label' => __( 'Customers', 'woocommerce' ),  
  218. 'href' => admin_url('users.php') 
  219. ),  
  220. array( 
  221. 'id' => 'coupons',  
  222. /** translators: woocommerce */ 
  223. 'label' => __( 'Coupons', 'woocommerce' ),  
  224. 'href' => admin_url('edit.php?post_type=shop_coupon') 
  225. ),  
  226. array( 
  227. 'id' => 'support',  
  228. /** translators: woocommerce */ 
  229. 'label' => __( 'Support', 'woocommerce' ),  
  230. 'href' => '#support' 
  231. )); 
  232.  
  233.