WCPGSK_Main

The Woocommerce Poor Guys Swiss Knife WCPGSK Main class.

Defined (1)

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

/classes/woocommerce-poor-guys-swiss-knife.php  
  1. class WCPGSK_Main { 
  2. private $dir; 
  3. private $assets_dir; 
  4. private $assets_url; 
  5. public $version; 
  6. private $file; 
  7.  
  8. /** 
  9. * Constructor function. 
  10. * @access public 
  11. * @since 1.1.0 
  12. * @return void 
  13. */ 
  14. public function __construct( $file ) { 
  15. global $wcpgsk_about; 
  16. $this->dir = dirname( $file ); 
  17. $this->file = $file; 
  18. $this->assets_dir = trailingslashit( $this->dir ) . 'assets'; 
  19. $this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $file ) ) ); 
  20. $this->load_plugin_textdomain();  
  21.  
  22. add_action( 'init', array( $this, 'load_localisation' ), 0 ); 
  23. // Run this on activation. 
  24. register_activation_hook( $this->file, array( $this, 'activation' ) ); 
  25. if ( is_admin() ) : // admin actions 
  26. // Hook into admin_init first 
  27. add_action( 'admin_init', array($this, 'wcpgsk_register_setting') ); 
  28. add_filter( 'plugin_action_links_'. plugin_basename($this->file), array($this, 'wcpgsk_admin_plugin_actions'), -10 ); 
  29. add_action( 'admin_menu', array($this, 'wcpgsk_admin_menu') );  
  30. $wcpgsk_about = new WCPGSK_About( $this->file ); 
  31. //add_action( 'add_meta_boxes', array($this, 'wcpgsk_add_meta_box_minmaxstep'), 10 ); 
  32. add_action('woocommerce_product_options_general_product_data', array( $this, 'wcpgsk_set_price_html' ), 99 ); 
  33.  
  34. add_action( 'woocommerce_product_write_panel_tabs', array( $this, 'wcpgsk_product_write_panel_tab' ), 99 ); 
  35. add_action( 'woocommerce_product_write_panels', array( $this, 'wcpgsk_product_write_panels' ), 99 ); 
  36. add_action( 'woocommerce_process_product_meta', array( $this, 'wcpgsk_process_product_meta' ), 99); 
  37. add_action( 'woocommerce_process_product_meta_variable', array( $this, 'wcpgsk_process_product_meta' ), 99); 
  38. add_action('wp_ajax_get_locale_field_form', array($this, 'get_locale_field_form_callback'));  
  39.  
  40. add_action('wp_ajax_wcpgsk_save_checkoutjs', array($this, 'wcpgsk_save_checkoutjs_callback'));  
  41. add_action( 'wcpgsk_settings_page_email', array( $this, 'wcpgsk_settings_page_email_wcpgsk' ), 10, 1 ); 
  42. add_action( 'wcpgsk_settings_page_labels', array( $this, 'wcpgsk_page_labels' ), 10, 1 ); 
  43.  
  44. endif; 
  45.  
  46. //billing and shipping filters 
  47. add_filter( 'woocommerce_billing_fields' , array($this, 'add_billing_custom_fields'), 10, 1 ); 
  48. add_filter( 'woocommerce_shipping_fields' , array($this, 'add_shipping_custom_fields'), 10, 1 ); 
  49.  
  50.  
  51. add_filter('woocommerce_admin_billing_fields', array($this, 'wcpgsk_admin_billing_fields'), 10, 1); 
  52. add_filter('woocommerce_admin_shipping_fields', array($this, 'wcpgsk_admin_shipping_fields'), 10, 1); 
  53.  
  54. add_filter( 'woocommerce_checkout_fields' , array($this, 'wcpgsk_checkout_fields_billing'), 10, 1 ); 
  55. add_filter( 'woocommerce_checkout_fields' , array($this, 'wcpgsk_checkout_fields_shipping'), 10, 1 ); 
  56. if ( function_exists('WC') ) : 
  57. add_filter( 'wc_address_i18n_params', array($this, 'wcpgsk_address_i18n_params'), 10, 1 );//$this->locale['default'] ); 
  58. //bind late to allow other plugins to add their fields 
  59. add_filter( 'woocommerce_country_locale_field_selectors', array($this, 'wcpgsk_country_locale_field_selectors'), 99, 1); 
  60. else : 
  61. add_filter( 'woocommerce_params', array($this, 'wcpgsk_address_i18n_params'), 10, 1 );// $woocommerce_params )  
  62. endif; 
  63.  
  64.  
  65. add_action( 'woocommerce_checkout_process', array($this, 'wcpgsk_checkout_process'), 9 ); 
  66.  
  67. add_filter( 'woocommerce_load_order_data', array($this, 'wcpgsk_load_order_data'), 5, 1); 
  68. add_action( 'woocommerce_checkout_init', array($this, 'wcpgsk_checkout_init'), 10, 1 ); 
  69.  
  70. add_action( 'woocommerce_email_after_order_table', array($this, 'wcpgsk_email_after_order_table') ); 
  71. add_action( 'woocommerce_order_details_after_order_table', array($this, 'wcpgsk_order_details_after_order_table'), 10, 1 ); 
  72. add_filter( 'woocommerce_address_to_edit', array($this, 'wcpgsk_address_to_edit'), 10, 1 ); 
  73. add_action( 'woocommerce_after_template_part', array($this, 'wcpgsk_after_template_part'), 10, 4 ); 
  74.  
  75. add_filter( 'woocommerce_process_myaccount_field_billing_postcode', array($this, 'wcpgsk_process_myaccount_field_billing_postcode'), 99, 1 ); 
  76. add_filter( 'woocommerce_process_myaccount_field_shipping_postcode', array($this, 'wcpgsk_process_myaccount_field_shipping_postcode'), 99, 1 ); 
  77.  
  78. add_filter( 'woocommerce_order_formatted_billing_address', array($this, 'wcpgsk_order_formatted_billing_address'), 99 ); 
  79. add_filter( 'woocommerce_order_formatted_shipping_address', array($this, 'wcpgsk_order_formatted_shipping_address'), 99 ); 
  80.  
  81. add_filter( 'woocommerce_user_column_billing_address', array($this, 'wcpgsk_order_formatted_billing_address'), 99 ); 
  82. add_filter( 'woocommerce_user_column_shipping_address', array($this, 'wcpgsk_order_formatted_shipping_address'), 99 ); 
  83.  
  84. add_filter( 'woocommerce_customer_meta_fields', array($this, 'wcpgsk_customer_meta_fields'), 99 ); 
  85. //add_filter( 'woocommerce_customer_meta_fields', array($this, 'wcpgsk_customer_meta_fields'), 99 ); 
  86.  
  87. add_filter( 'woocommerce_email_headers', array( $this, 'wcpgsk_email_headers' ), PHP_INT_MAX, 3 ); 
  88.  
  89. add_action( 'wp_print_scripts', array($this, 'wcpgsk_handle_scripts'), 100 ); 
  90. add_action( 'wp_enqueue_scripts', array($this, 'wcpgsk_degenerate'), 100 );  
  91.  
  92. add_filter( 'woocommerce_sale_flash', array( $this, 'wcpgsk_sale_flash' ), 10, 3 ); 
  93. add_action( 'woocommerce_proceed_to_checkout', array( $this, 'wcpgsk_after_cart' ), 10 ); 
  94.  
  95. add_action( 'woocommerce_init', array( $this, 'wcpgsk_empty_cart' ), PHP_INT_MAX ); 
  96. add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'wcpgsk_checkout_update_order_meta' ), 10, 2 ); 
  97.  
  98. add_filter('woocommerce_get_price_html', array( $this, 'wcpgsk_get_price_html' ), 10, 2 ); 
  99. add_filter('woocommerce_empty_price_html', array( $this, 'wcpgsk_empty_price_html' ), PHP_INT_MAX, 2 ); 
  100. add_filter('woocommerce_free_sale_price_html', array( $this, 'wcpgsk_free_sale_price_html' ), PHP_INT_MAX, 2 ); 
  101. add_filter('woocommerce_free_price_html', array( $this, 'wcpgsk_free_price_html' ), PHP_INT_MAX, 2 ); 
  102. add_filter('woocommerce_after_my_account', array( $this, 'wcpgsk_after_my_account' ), 10 ); 
  103.  
  104.  
  105. /** 
  106. * Process empty cart request 
  107. * @since 1.9.7 
  108. * @access public 
  109. */ 
  110. public function wcpgsk_empty_cart() { 
  111. if ( isset( $_POST['wcpgsk_empty_cart'] ) ) {  
  112. global $woocommerce; 
  113. $woocommerce->cart->empty_cart(); 
  114.  
  115. /** 
  116. * Add empty cart form 
  117. * @since 1.9.7 
  118. * @access public 
  119. */ 
  120. public function wcpgsk_after_cart( ) { 
  121. $options = get_option( 'wcpgsk_settings' ); 
  122. if ( isset( $options['cart']['addemptycart'] ) && $options['cart']['addemptycart'] ) : 
  123. if ( isset( $options['process']['confirmemptycart'] ) && !empty( $options['process']['confirmemptycart'] ) ) : 
  124. $eclabel = isset( $options['process']['emptycartlabel'] ) && !empty( $options['process']['emptycartlabel'] ) ? $options['process']['emptycartlabel'] : "Empty cart";  
  125. $cclabel = isset( $options['process']['confirmemptycart'] ) && !empty( $options['process']['confirmemptycart'] ) ? $options['process']['confirmemptycart'] : "Yes, empty cart";  
  126. echo '<div class="wcpgsk_empty_cart"><input type="button" class="button" style="width:100%" id="wcpgsk_confirm_empty_cart" value="' . __( $eclabel, WCPGSK_DOMAIN) . '"/></div>'; 
  127. echo '<div class="wcpgsk_empty_cart"><input type="submit" class="button" style="display:none;width:100%" id="wcpgsk_empty_cart" name="wcpgsk_empty_cart" value="' . __( $cclabel, WCPGSK_DOMAIN) . '"></div>'; 
  128. else : 
  129. $eclabel = isset( $options['process']['emptycartlabel'] ) && !empty( $options['process']['emptycartlabel'] ) ? $options['process']['emptycartlabel'] : "Empty cart";  
  130. echo '<div class="wcpgsk_empty_cart"><input type="submit" class="button" name="wcpgsk_empty_cart" value="' . __( $eclabel, WCPGSK_DOMAIN) . '"></div>'; 
  131. endif; 
  132. endif; 
  133.  
  134.  
  135.  
  136. /** 
  137. * Sale flash text 
  138. * @since 1.9.7 
  139. * @access public 
  140. * @param string $flash 
  141. * @param mixed $post 
  142. * @param mixed $product 
  143. * @return string 
  144. */ 
  145. public function wcpgsk_sale_flash( $flash, $post, $product ) { 
  146. $options = get_option( 'wcpgsk_settings' );  
  147. //$lp = get_product( $product->post->ID ); 
  148. if ( $product->get_price() === '' || $product->get_price() == 0 ) : 
  149. return ''; 
  150. endif;  
  151. $product_id = $product->post->ID; 
  152. $onsale_label = get_post_meta($product_id, '_wcpgsk_onsale_html', true); 
  153. if ( isset( $onsale_label ) && !empty( $onsale_label ) ) : 
  154. return '<span class="onsale">' . __( $onsale_label, WCPGSK_DOMAIN ) . '</span>'; 
  155. endif; 
  156.  
  157. if ( isset( $options['process']['onsalelabel'] ) && !empty( $options['process']['onsalelabel'] ) ) : 
  158. $flash = '<span class="onsale">' . __( $options['process']['onsalelabel'], WCPGSK_DOMAIN ) . '</span>'; 
  159. endif; 
  160. return $flash; 
  161.  
  162. /** 
  163. * Add additional email headers 
  164. * @since 1.9.7 
  165. * @access public 
  166. * @param string $headers (existing) 
  167. * @param string $context 
  168. * @param mixed $email 
  169. * @return string 
  170. */ 
  171. public function wcpgsk_email_headers( $headers = '', $context = '', $email = array() ) { 
  172. $options = get_option( 'wcpgsk_settings' ); 
  173. if ( isset( $headers ) && !empty( $headers ) ) : 
  174. $headers = explode( "\r\n", $headers ); 
  175. else : 
  176. $headers = array(); 
  177. endif; 
  178. if ( isset( $options['email']['wc_cc_email'] ) && !empty( $options['email']['wc_cc_email'] ) && is_email( $options['email']['wc_cc_email'] ) ) : 
  179. $headers[] = "Cc: " . $options['email']['wc_cc_email']; 
  180. endif; 
  181. if ( isset($options['email']['wc_bcc_email']) && !empty( $options['email']['wc_bcc_email'] ) && is_email( $options['email']['wc_bcc_email'] ) ) :  
  182. $headers[] = "Bcc: " . $options['email']['wc_bcc_email'];  
  183. endif; 
  184.  
  185. return implode( "\r\n", $headers); 
  186.  
  187. /** 
  188. * Email configuration settings 
  189. * @since 1.9.7 
  190. * @access public 
  191. * @param array $options  
  192. */ 
  193. public function wcpgsk_settings_page_email_wcpgsk( $options ) { 
  194. if ( isset( $options['email']['wc_cc_email'] ) && !empty( $options['email']['wc_cc_email'] ) ) :  
  195. $emails = explode( ', ', str_replace( ';', ', ', $options['email']['wc_cc_email'] ) ); 
  196. $options['email']['wc_cc_email'] = isset( $emails[0] ) ? $emails[0] : ''; 
  197. else : 
  198. $options['email']['wc_cc_email'] = '';  
  199. endif; 
  200. if ( isset($options['email']['wc_bcc_email']) && !empty( $options['email']['wc_bcc_email'] ) ) :  
  201. $emails = explode( ', ', str_replace( ';', ', ', $options['email']['wc_bcc_email'] ) ); 
  202. $options['email']['wc_bcc_email'] = isset( $emails[0] ) ? $emails[0] : ''; 
  203. else : 
  204. $options['email']['wc_bcc_email'] = ''; 
  205. endif; 
  206. ?> 
  207. <h3 class="wcpgsk_acc_header"><?php echo __('Email Settings', WCPGSK_DOMAIN); ?></h3> 
  208. <div> 
  209. <table class="widefat" border="1" > 
  210. <thead> 
  211. <tr> 
  212. <th><?php _e('Settings Name', WCPGSK_DOMAIN); ?></th> 
  213. <th><?php _e('Data', WCPGSK_DOMAIN); ?></th>  
  214. <th><?php _e('Comments', WCPGSK_DOMAIN); ?></th> 
  215. </tr> 
  216. </thead> 
  217. <tbody> 
  218. <tr> 
  219. <td width="25%"><?php _e( 'Carbon Copy Email (CC) Recipient', WCPGSK_DOMAIN ); ?></td> 
  220. <td> 
  221. <input name="wcpgsk_settings[email][wc_cc_email]" id="wcpgsk_wc_cc_email" type="email" value="<?php echo $options['email']['wc_cc_email'] ?>" class="regular-text" /> 
  222. </td> 
  223. <td> 
  224. <span class="description"><?php _e('Specify a valid email address that will receive copies of all WooCommerce emails.', WCPGSK_DOMAIN); ?></span> 
  225. </td> 
  226. </tr> 
  227. <tr> 
  228. <td width="25%"><?php _e( 'Blind Carbon Copy (BCC) Email Recipient', WCPGSK_DOMAIN ); ?></td> 
  229. <td> 
  230. <input name="wcpgsk_settings[email][wc_bcc_email]" id="wcpgsk_wc_bcc_email" type="email" value="<?php echo $options['email']['wc_bcc_email'] ?>" class="regular-text" /> 
  231. </td> 
  232. <td> 
  233. <span class="description"><?php _e('Specify a valid email address that will receive hidden copies of all WooCommerce emails.', WCPGSK_DOMAIN); ?></span> 
  234. </td> 
  235. </tr> 
  236. <tr><td colspan="3"><?php _e('WooCommerce Rich Guys Swiss Knife includes more email options, e.g. context dependent cc and bcc email recipients, etc.', WCPGSK_DOMAIN); ?></td></tr>  
  237. </tbody> 
  238. </table> 
  239. <?php submit_button( __( 'Save Changes', WCPGSK_DOMAIN ) ); ?> 
  240.  
  241. </div> 
  242. <?php 
  243.  
  244.  
  245. /** 
  246. * Add extended amount information 
  247. * @since 2.1.0 
  248. * @access public 
  249. * @output fields 
  250. */ 
  251. public function wcpgsk_set_price_html() { 
  252. woocommerce_wp_text_input(array('id' => '_wcpgsk_button_label', 'label' => __('Specify button label', WCPGSK_DOMAIN) )); 
  253. woocommerce_wp_text_input(array('id' => '_wcpgsk_extend_price', 'label' => __('Specify extended price data', WCPGSK_DOMAIN) )); 
  254. $placements = array(  
  255. 'after' => __( 'After price', WCPGSK_DOMAIN ),  
  256. 'before' => __( 'Before price', WCPGSK_DOMAIN ),  
  257. 'newline' => __( 'On newline', WCPGSK_DOMAIN ),  
  258. ); 
  259. woocommerce_wp_select(array('id' => '_wcpgsk_extend_price_placement', 'label' => __('Select placement of extended price data', WCPGSK_DOMAIN), 'options' => $placements )); 
  260. woocommerce_wp_text_input(array('id' => '_wcpgsk_onsale_html', 'label' => __('Specify on sale label', WCPGSK_DOMAIN) )); 
  261. woocommerce_wp_text_input(array('id' => '_wcpgsk_empty_price_html', 'label' => __('Specify empty price label', WCPGSK_DOMAIN) )); 
  262. woocommerce_wp_text_input(array('id' => '_wcpgsk_free_price_html', 'label' => __('Specify free price label', WCPGSK_DOMAIN) )); 
  263. woocommerce_wp_text_input(array('id' => '_wcpgsk_free_sale_html', 'label' => __('Specify free sales label', WCPGSK_DOMAIN) )); 
  264.  
  265. /** 
  266. * Display extended price information 
  267. * @since 2.1.0 
  268. * @access public 
  269. * @param string $price 
  270. * @param mixed $product 
  271. * @return string $price extended 
  272. */ 
  273. public function wcpgsk_get_price_html($price, $product) { 
  274. $product_id = $product->post->ID; 
  275. $extend_price_data = get_post_meta($product_id, '_wcpgsk_extend_price', true); 
  276. if ( isset( $extend_price_data ) && !empty( $extend_price_data ) ) : 
  277. $extend_price_placement = get_post_meta($product_id, '_wcpgsk_extend_price_placement', true); 
  278. switch ( $extend_price_placement ) : 
  279. case "before" : 
  280. $price = '<span class="wcpgsk-extend-price-data">' . __( $extend_price_data, WCPGSK_DOMAIN ) . '</span> ' . $price; 
  281. break; 
  282. case "newline" : 
  283. $price = $price . '<div class="wcpgsk-extend-price-data">' . __( $extend_price_data, WCPGSK_DOMAIN ) . '</div>'; 
  284. break; 
  285. default : 
  286. $price = $price . ' <span class="wcpgsk-extend-price-data">' . __( $extend_price_data, WCPGSK_DOMAIN ) . '</span>';  
  287. break; 
  288. endswitch; 
  289. endif; 
  290. if ( $product->managing_stock() ) : 
  291. $hdl_backorder = $product->get_availability(); 
  292. $options = get_option( 'wcpgsk_settings' );  
  293. if ( isset( $hdl_backorder ) && $hdl_backorder['class'] == 'available-on-backorder' && isset( $options['process']['backorderlabel'] ) && !empty( $options['process']['backorderlabel'] ) ) : 
  294. $price = $price . '<div class="wcpgsk-extend-price-data">' . __( $options['process']['backorderlabel'], WCPGSK_DOMAIN ) . '</div>'; 
  295. endif; 
  296. endif; 
  297. return $price; 
  298.  
  299. /** 
  300. * Display empty price label if defined as label or for product 
  301. * @since 2.1.0 
  302. * @access public 
  303. * @param string $empty 
  304. * @param mixed $product 
  305. * @return string $price label for empty 
  306. */ 
  307. public function wcpgsk_empty_price_html( $empty, $product ) { 
  308. $options = get_option( 'wcpgsk_settings' );  
  309. $product_id = $product->post->ID; 
  310. $g_empty_price = isset( $options['process']['empty_price_html'] ) && !empty( $options['process']['empty_price_html'] ) ? $options['process']['empty_price_html'] : ''; 
  311. $p_empty_price = get_post_meta($product_id, '_wcpgsk_empty_price_html', true); 
  312. if ( isset( $p_empty_price ) && !empty( $p_empty_price ) ) : 
  313. return $p_empty_price; 
  314. endif; 
  315. return $g_empty_price; 
  316.  
  317. /** 
  318. * Display free sales price label if defined for a product 
  319. * @since 2.1.0 
  320. * @access public 
  321. * @param string $empty 
  322. * @param mixed $product 
  323. * @return string $price label for empty 
  324. */ 
  325. public function wcpgsk_free_sale_price_html( $price, $product ) { 
  326. $product_id = $product->post->ID; 
  327. $free_sales_label = get_post_meta($product_id, '_wcpgsk_free_sale_html', true); 
  328. if ( isset( $free_sales_label ) && !empty( $free_sales_label ) ) : 
  329. $price = str_replace( __( 'Free!', 'woocommerce' ), __( $free_sales_label, WCPGSK_DOMAIN ), $price ); 
  330. endif; 
  331. return $price; 
  332.  
  333. /** 
  334. * Display free price label if defined for a product 
  335. * @since 2.1.0 
  336. * @access public 
  337. * @param string $empty 
  338. * @param mixed $product 
  339. * @return string $price label for empty 
  340. */ 
  341. public function wcpgsk_free_price_html( $price, $product ) { 
  342. $product_id = $product->post->ID; 
  343. $free_price_label = get_post_meta($product_id, '_wcpgsk_free_price_html', true); 
  344. if ( isset( $free_price_label ) && !empty( $free_price_label ) ) : 
  345. $price = __( $free_price_label, WCPGSK_DOMAIN ); 
  346. endif; 
  347. return $price; 
  348.  
  349. /** 
  350. * Label configuration settings 
  351. * @since 1.9.7 
  352. * @access public 
  353. * @param array $options  
  354. */ 
  355. public function wcpgsk_page_labels( $options ) { 
  356. ?> 
  357. <h3 class="wcpgsk_acc_header"><?php echo __('Label Settings', WCPGSK_DOMAIN); ?></h3> 
  358. <div> 
  359. <table class="widefat" border="1" > 
  360. <thead> 
  361. <tr> 
  362. <th><?php _e('Settings Name', WCPGSK_DOMAIN); ?></th> 
  363. <th><?php _e('Data', WCPGSK_DOMAIN); ?></th>  
  364. <th><?php _e('Comments', WCPGSK_DOMAIN); ?></th> 
  365. </tr> 
  366. </thead> 
  367. <tbody> 
  368. <?php do_action( 'wcpgsk_settings_labels_before', $options ); ?> 
  369. <tr> 
  370. <td width="25%"><?php _e( 'On Sale Label', WCPGSK_DOMAIN ); ?></td> 
  371. <td> 
  372. <input name="wcpgsk_settings[process][onsalelabel]" type="text" id="wcpgsk_onsalelabel" value="<?php echo $options['process']['onsalelabel'] ?>" class="regular-text" /> 
  373. </td> 
  374. <td> 
  375. <span class="description"><?php _e('Define the on sale label. (You may need to adapt css!)', WCPGSK_DOMAIN); ?></span> 
  376. </td> 
  377. </tr> 
  378. <tr> 
  379. <td width="25%"><?php _e( 'Backorder Label', WCPGSK_DOMAIN ); ?></td> 
  380. <td> 
  381. <input name="wcpgsk_settings[process][backorderlabel]" type="text" id="wcpgsk_backorderlabel" value="<?php echo $options['process']['backorderlabel'] ?>" class="regular-text" /> 
  382. </td> 
  383. <td> 
  384. <span class="description"><?php _e('Define the backorder label. (You may need to adapt css!)', WCPGSK_DOMAIN); ?></span> 
  385. </td> 
  386. </tr> 
  387. <tr> 
  388. <td width="25%"><?php _e( 'Add to Cart Button Label', WCPGSK_DOMAIN ); ?></td> 
  389. <td> 
  390. <input name="wcpgsk_settings[process][fastcheckoutbtn]" type="text" id="wcpgsk_fastcheckout_btn" value="<?php echo $options['process']['fastcheckoutbtn'] ?>" class="regular-text" /> 
  391. </td> 
  392. <td> 
  393. <span class="description"><?php _e('Define the label for the Add to Cart button.', WCPGSK_DOMAIN); ?></span> 
  394. </td> 
  395. </tr> 
  396. <tr> 
  397. <td width="25%"><?php _e( 'Read more Button Label', WCPGSK_DOMAIN ); ?></td> 
  398. <td> 
  399. <input name="wcpgsk_settings[process][readmorebtn]" type="text" id="wcpgsk_readmore_btn" value="<?php echo $options['process']['readmorebtn'] ?>" class="regular-text" /> 
  400. </td> 
  401. <td> 
  402. <span class="description"><?php _e('Define the label for the Read more button.', WCPGSK_DOMAIN); ?></span> 
  403. </td> 
  404. </tr> 
  405. <tr> 
  406. <td width="25%"><?php _e( 'View products Button Label', WCPGSK_DOMAIN ); ?></td> 
  407. <td> 
  408. <input name="wcpgsk_settings[process][viewproductsbtn]" type="text" id="wcpgsk_viewproducts_btn" value="<?php echo $options['process']['viewproductsbtn'] ?>" class="regular-text" /> 
  409. </td> 
  410. <td> 
  411. <span class="description"><?php _e('Define the label for the View products button.', WCPGSK_DOMAIN); ?></span> 
  412. </td> 
  413. </tr> 
  414. <tr> 
  415. <td width="25%"><?php _e( 'Select options Button Label', WCPGSK_DOMAIN ); ?></td> 
  416. <td> 
  417. <input name="wcpgsk_settings[process][selectoptionsbtn]" type="text" id="wcpgsk_selectoptions_btn" value="<?php echo $options['process']['selectoptionsbtn'] ?>" class="regular-text" /> 
  418. </td> 
  419. <td> 
  420. <span class="description"><?php _e('Define the label for the Select options button.', WCPGSK_DOMAIN); ?></span> 
  421. </td> 
  422. </tr> 
  423. <tr> 
  424. <td width="25%"><?php _e( 'Buy product Button Label', WCPGSK_DOMAIN ); ?></td> 
  425. <td> 
  426. <input name="wcpgsk_settings[process][buyproductbtn]" type="text" id="wcpgsk_buyproduct_btn" value="<?php echo $options['process']['buyproductbtn'] ?>" class="regular-text" /> 
  427. </td> 
  428. <td> 
  429. <span class="description"><?php _e('Define the label for the Buy product button.', WCPGSK_DOMAIN); ?></span> 
  430. </td> 
  431. </tr> 
  432. <tr> 
  433. <td width="25%"><?php _e( 'Out of stock Button Label', WCPGSK_DOMAIN ); ?></td> 
  434. <td> 
  435. <input name="wcpgsk_settings[process][outofstockbtn]" type="text" id="wcpgsk_outofstock_btn" value="<?php echo $options['process']['outofstockbtn'] ?>" class="regular-text" /> 
  436. </td> 
  437. <td> 
  438. <span class="description"><?php _e('Define the label for the Out of stock button.', WCPGSK_DOMAIN); ?></span> 
  439. </td> 
  440. </tr> 
  441. <tr> 
  442. <td width="25%"><?php _e( 'Tax Label', WCPGSK_DOMAIN ); ?></td> 
  443. <td> 
  444. <input name="wcpgsk_settings[filters][woocommerce_countries_tax_or_vat]" type="text" id="wcpgsk_woocommerce_countries_tax_or_vat" value="<?php echo $options['filters']['woocommerce_countries_tax_or_vat'] ?>" class="regular-text" /> 
  445. </td> 
  446. <td> 
  447. <span class="description"><?php _e('Define the tax label.', WCPGSK_DOMAIN); ?></span> 
  448. </td> 
  449. </tr> 
  450. <tr> 
  451. <td width="25%"><?php _e( 'Includes tax message', WCPGSK_DOMAIN ); ?></td> 
  452. <td> 
  453. <input name="wcpgsk_settings[filters][woocommerce_countries_inc_tax_or_vat]" type="text" id="wcpgsk_woocommerce_countries_inc_tax_or_vat" value="<?php echo $options['filters']['woocommerce_countries_inc_tax_or_vat'] ?>" class="regular-text" /> 
  454. </td> 
  455. <td> 
  456. <span class="description"><?php _e('Define the tax included message.', WCPGSK_DOMAIN); ?></span> 
  457. </td> 
  458. </tr> 
  459. <tr> 
  460. <td width="25%"><?php _e( 'Tax excluded message', WCPGSK_DOMAIN ); ?></td> 
  461. <td> 
  462. <input name="wcpgsk_settings[filters][woocommerce_countries_ex_tax_or_vat]" type="text" id="wcpgsk_woocommerce_countries_ex_tax_or_vat" value="<?php echo $options['filters']['woocommerce_countries_ex_tax_or_vat'] ?>" class="regular-text" /> 
  463. </td> 
  464. <td> 
  465. <span class="description"><?php _e('Define the tax excluded message.', WCPGSK_DOMAIN); ?></span> 
  466. </td> 
  467. </tr> 
  468. <tr> 
  469. <td width="25%"><?php _e( 'Product Description Tab Label', WCPGSK_DOMAIN ); ?></td> 
  470. <td> 
  471. <input name="wcpgsk_settings[filters][woocommerce_product_description_tab_title]" type="text" id="wcpgsk_woocommerce_product_description_tab_title" value="<?php echo $options['filters']['woocommerce_product_description_tab_title'] ?>" class="regular-text" /> 
  472. </td> 
  473. <td> 
  474. <span class="description"><?php _e('Define the label for the product description tab.', WCPGSK_DOMAIN); ?></span> 
  475. </td> 
  476. </tr> 
  477. <tr> 
  478. <td width="25%"><?php _e( 'Product Description Header', WCPGSK_DOMAIN ); ?></td> 
  479. <td> 
  480. <input name="wcpgsk_settings[filters][woocommerce_product_description_heading]" type="text" id="wcpgsk_woocommerce_product_description_heading" value="<?php echo $options['filters']['woocommerce_product_description_heading'] ?>" class="regular-text" /> 
  481. </td> 
  482. <td> 
  483. <span class="description"><?php _e('Define the product description header.', WCPGSK_DOMAIN); ?></span> 
  484. </td> 
  485. </tr> 
  486. <tr> 
  487. <td width="25%"><?php _e( 'Product Additional Information Tab Label', WCPGSK_DOMAIN ); ?></td> 
  488. <td> 
  489. <input name="wcpgsk_settings[filters][woocommerce_product_additional_information_tab_title]" type="text" id="wcpgsk_woocommerce_product_additional_information_tab_title" value="<?php echo $options['filters']['woocommerce_product_additional_information_tab_title'] ?>" class="regular-text" /> 
  490. </td> 
  491. <td> 
  492. <span class="description"><?php _e('Define the label for the product additional information tab.', WCPGSK_DOMAIN); ?></span> 
  493. </td> 
  494. </tr> 
  495. <tr> 
  496. <td width="25%"><?php _e( 'Product Additional Information Header', WCPGSK_DOMAIN ); ?></td> 
  497. <td> 
  498. <input name="wcpgsk_settings[filters][woocommerce_product_additional_information_heading]" type="text" id="wcpgsk_woocommerce_product_additional_information_heading" value="<?php echo $options['filters']['woocommerce_product_additional_information_heading'] ?>" class="regular-text" /> 
  499. </td> 
  500. <td> 
  501. <span class="description"><?php _e('Define the product additional information header.', WCPGSK_DOMAIN); ?></span> 
  502. </td> 
  503. </tr> 
  504. <tr> 
  505. <td><?php _e('Set Order Button Text', WCPGSK_DOMAIN); ?>:</td> 
  506. <td> 
  507. <input name="wcpgsk_settings[filters][woocommerce_order_button_text]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['filters']['woocommerce_order_button_text'])) echo esc_attr( $options['filters']['woocommerce_order_button_text'] ); ?>" class="regular-text" /> 
  508. </td> 
  509. <td> 
  510. <span class="description"><?php _e('Set the order button text.', WCPGSK_DOMAIN); ?></span> 
  511. </td> 
  512. </tr> 
  513. <tr> 
  514. <td><?php _e('Pay Order Button Text', WCPGSK_DOMAIN); ?>:</td> 
  515. <td> 
  516. <input name="wcpgsk_settings[filters][woocommerce_pay_order_button_text]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['filters']['woocommerce_pay_order_button_text'])) echo esc_attr( $options['filters']['woocommerce_pay_order_button_text'] ); ?>" class="regular-text" /> 
  517. </td> 
  518. <td> 
  519. <span class="description"><?php _e('Set the pay order button text.', WCPGSK_DOMAIN); ?></span> 
  520. </td> 
  521. </tr> 
  522.  
  523. <tr> 
  524. <td><?php _e('Set Login required message', WCPGSK_DOMAIN); ?>:</td> 
  525. <td> 
  526. <input name="wcpgsk_settings[filters][woocommerce_checkout_must_be_logged_in_message]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['filters']['woocommerce_checkout_must_be_logged_in_message'])) echo esc_attr( $options['filters']['woocommerce_checkout_must_be_logged_in_message'] ); ?>" class="regular-text" /> 
  527. </td> 
  528. <td> 
  529. <span class="description"><?php _e('Change the login required message for the checkout form.', WCPGSK_DOMAIN); ?></span> 
  530. </td> 
  531. </tr> 
  532. <tr> 
  533. <td><?php _e('Set Login possible message', WCPGSK_DOMAIN); ?>:</td> 
  534. <td> 
  535. <input name="wcpgsk_settings[filters][woocommerce_checkout_login_message]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['filters']['woocommerce_checkout_login_message'])) echo esc_attr( $options['filters']['woocommerce_checkout_login_message'] ); ?>" class="regular-text" /> 
  536. </td> 
  537. <td> 
  538. <span class="description"><?php _e('Change the returning customer login message for the checkout form.', WCPGSK_DOMAIN); ?></span> 
  539. </td> 
  540. </tr> 
  541. <tr> 
  542. <td><?php _e('Set Coupon message', WCPGSK_DOMAIN); ?>:</td> 
  543. <td> 
  544. <input name="wcpgsk_settings[filters][woocommerce_checkout_coupon_message]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['filters']['woocommerce_checkout_coupon_message'])) echo esc_attr( $options['filters']['woocommerce_checkout_coupon_message'] ); ?>" class="regular-text" /> 
  545. </td> 
  546. <td> 
  547. <span class="description"><?php _e('Change the coupon message for the checkout form.', WCPGSK_DOMAIN); ?></span> 
  548. </td> 
  549. </tr> 
  550. <tr> 
  551. <td><?php _e('Set Coupon link message', WCPGSK_DOMAIN); ?>:</td> 
  552. <td> 
  553. <input name="wcpgsk_settings[filters][woocommerce_checkout_coupon_link_message]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['filters']['woocommerce_checkout_coupon_link_message'])) echo esc_attr( $options['filters']['woocommerce_checkout_coupon_link_message'] ); ?>" class="regular-text" /> 
  554. </td> 
  555. <td> 
  556. <span class="description"><?php _e('Change the coupon link message for the checkout form. (WC 2.2+ only)', WCPGSK_DOMAIN); ?></span> 
  557. </td> 
  558. </tr> 
  559. <tr> 
  560. <td><?php _e('Define order received message', WCPGSK_DOMAIN); ?>:</td> 
  561. <td> 
  562. <input name="wcpgsk_settings[filters][woocommerce_thankyou_order_received_text]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['filters']['woocommerce_thankyou_order_received_text'])) echo esc_attr( $options['filters']['woocommerce_thankyou_order_received_text'] ); ?>" class="regular-text" /> 
  563. </td> 
  564. <td> 
  565. <span class="description"><?php _e('Define the order received thank you message.', WCPGSK_DOMAIN); ?></span> 
  566. </td> 
  567. </tr> 
  568. <tr> 
  569. <td><?php _e('Define alternative placeholder image url', WCPGSK_DOMAIN); ?>:</td> 
  570. <td> 
  571. <input name="wcpgsk_settings[filters][woocommerce_placeholder_img_src]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['filters']['woocommerce_placeholder_img_src'])) echo esc_attr( $options['filters']['woocommerce_placeholder_img_src'] ); ?>" class="regular-text" /> 
  572. </td> 
  573. <td> 
  574. <span class="description"><?php _e('Define alternative placeholder image url.', WCPGSK_DOMAIN); ?></span> 
  575. </td> 
  576. </tr> 
  577. <tr> 
  578. <td><?php _e('Define empty price label', WCPGSK_DOMAIN); ?>:</td> 
  579. <td> 
  580. <input name="wcpgsk_settings[process][empty_price_html]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['process']['empty_price_html'])) echo esc_attr( $options['process']['empty_price_html'] ); ?>" class="regular-text" /> 
  581. </td> 
  582. <td> 
  583. <span class="description"><?php _e('Define a empty price label.', WCPGSK_DOMAIN); ?></span> 
  584. </td> 
  585. </tr> 
  586. <?php do_action( 'wcpgsk_settings_labels_after', $options ); ?>  
  587. </tbody> 
  588. </table> 
  589. <?php submit_button( __( 'Save Changes', WCPGSK_DOMAIN ) ); ?> 
  590.  
  591. </div> 
  592. <?php  
  593.  
  594. /** 
  595. * Hook available and WCPGSK configured WooCommerce filters 
  596. * @since 1.9.2 
  597. */ 
  598. public function wcpgsk_hook_woocommerce_filters() { 
  599. $options = get_option( 'wcpgsk_settings' ); 
  600. if ( !empty( $options['filters'] ) ) : 
  601. foreach ( $options['filters'] as $filter => $value ) : 
  602. //do it late 
  603. add_filter( $filter, array( $this, 'wcpgsk_apply_woocommerce_filter' ), 1 ); 
  604. endforeach; 
  605. endif; 
  606.  
  607.  
  608.  
  609. /** 
  610. * Run available WooCommerce filters 
  611. * @since 1.9.2 
  612. * @changed 2.1.0 
  613. * @return configured string value 
  614. */ 
  615. public function wcpgsk_apply_woocommerce_filter( $filterval, $param2 = null ) { 
  616. $options = get_option( 'wcpgsk_settings' ); 
  617.  
  618. $the_filter = current_filter(); 
  619. if ( isset( $options['filters'][ $the_filter ] ) ) { 
  620. $configval = $options['filters'][ $the_filter ]; 
  621. switch ( $the_filter ) : 
  622. case "woocommerce_create_account_default_checked" : 
  623. if ( $configval ) : 
  624. $filterval = true; 
  625. else : 
  626. $filterval = false; 
  627. endif; 
  628. break; 
  629. case "loop_shop_per_page" : 
  630. if ( !empty( $configval ) && is_numeric( $configval ) && intval( $configval ) > 0 ) : 
  631. $filterval = intval( $configval ); 
  632. endif; 
  633. break; 
  634. case "loop_shop_columns" : 
  635. if ( !empty( $configval ) && is_numeric( $configval ) && intval( $configval ) > 0 ) : 
  636. $filterval = intval( $configval ); 
  637. endif; 
  638. break; 
  639. case "woocommerce_product_thumbnails_columns" : 
  640. if ( !empty( $configval ) && is_numeric( $configval ) && intval( $configval ) > 0 ) : 
  641. $filterval = intval( $configval ); 
  642. endif; 
  643. break; 
  644.  
  645. case "woocommerce_checkout_coupon_message" : 
  646. $current_wc_version = get_option( 'woocommerce_db_version' ); 
  647.  
  648. if ( version_compare( $current_wc_version, '2.2.0', '>=' ) ) : 
  649. //make translatable 
  650. if ( !empty( $configval ) ) : 
  651. if ( isset( $options['filters']['woocommerce_checkout_coupon_link_message'] ) && !empty( $options['filters']['woocommerce_checkout_coupon_link_message'] ) ) : 
  652. $filterval = __($configval, WCPGSK_DOMAIN) . ' <a href="#" class="showcoupon">' . __( $options['filters']['woocommerce_checkout_coupon_link_message'], WCPGSK_DOMAIN ) . '</a>'; 
  653. else : 
  654. $filterval = __($configval, WCPGSK_DOMAIN) . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>';  
  655. endif; 
  656. endif; 
  657. else : 
  658. //make translatable 
  659. if ( !empty( $configval ) ) : 
  660. $filterval = __($configval, WCPGSK_DOMAIN); 
  661. endif; 
  662. endif; 
  663.  
  664. break; 
  665. case "woocommerce_product_description_heading" : 
  666. $filterval = __($configval, WCPGSK_DOMAIN); 
  667. break; 
  668. case "woocommerce_product_additional_information_heading" : 
  669. $filterval = __($configval, WCPGSK_DOMAIN); 
  670. break; 
  671. default : 
  672. //make translatable 
  673. if ( !empty( $configval ) ) : 
  674. $filterval = __($configval, WCPGSK_DOMAIN); 
  675. endif; 
  676. break; 
  677. endswitch; 
  678. }  
  679. return $filterval; 
  680.  
  681.  
  682. /** 
  683. * Register Product Tab for Min/Max/Step Configuration for Simple and Variable products 
  684. * @access public 
  685. * @since 1.6.0 
  686. * @echo html 
  687. */ 
  688. public function wcpgsk_product_write_panel_tab() { 
  689. global $post; 
  690. $options = get_option( 'wcpgsk_settings' ); 
  691. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) :  
  692. if ( $terms = wp_get_object_terms( $post->ID, 'product_type' ) ) 
  693. $product_type = sanitize_title( current( $terms )->name ); 
  694. else 
  695. $product_type = 'simple';  
  696. if ( $product_type === 'simple' || $product_type === 'variable' ) : 
  697. echo "<li class=\"wcpgsk_product_tab\"><a class=\"icon16 icon-media\" href=\"#wcpgsk_data_tab\">" . __( 'Product Cart Quantities', WCPGSK_DOMAIN ) . "</a></li>"; 
  698. endif; 
  699. endif; 
  700.  
  701. /** 
  702. * Save checkout js 
  703. *  
  704. * @access public 
  705. * @since 1.8.1 
  706. * @return nothing  
  707. */ 
  708. public function wcpgsk_save_checkoutjs_callback() { 
  709. global $wpdb; 
  710. $data = $_POST['checkoutjs'];//json_decode(str_replace('\\"', '"', $_POST['jsondata']), true); 
  711.  
  712. $checkoutjs = $_POST['checkoutjs']; 
  713. if ( isset($checkoutjs) ) : 
  714. update_option('wcpgsk_checkoutjs', stripslashes($checkoutjs)); 
  715. echo __('js saved', WCPGSK_DOMAIN); 
  716. endif; 
  717. $this->phpdie(); 
  718.  
  719.  
  720. /** 
  721. * Helper function: mimics 2.1.x for 2.0.x installations and calls +2.1 function directly if available 
  722. *  
  723. * @access public 
  724. * @since 1.7.1 
  725. * @return array of localizable fields  
  726. */ 
  727. public function wcpgsk_get_country_locale_field_selectors() { 
  728. if ( function_exists('WC') ) : 
  729. return WC()->countries->get_country_locale_field_selectors(); 
  730. else : 
  731. //we need this for internal usage... on the frontend fields are hardcode in WC < 2.1 into js 
  732. $locale_fields = array ( 
  733. 'address_1' => '#billing_address_1_field, #shipping_address_1_field',  
  734. 'address_2' => '#billing_address_2_field, #shipping_address_2_field',  
  735. 'state' => '#billing_state_field, #shipping_state_field',  
  736. 'postcode' => '#billing_postcode_field, #shipping_postcode_field',  
  737. 'city' => '#billing_city_field, #shipping_city_field' 
  738. ); 
  739. //@TODO: Do we really want to filter in WC < 2.1? 
  740. return apply_filters( 'woocommerce_country_locale_field_selectors', $locale_fields ); 
  741. endif; 
  742.  
  743. /** 
  744. * Helper function: not really necessary... 
  745. * @access public 
  746. * @since 1.7.1 
  747. * @return array localization config 
  748. */ 
  749. public function wcpgsk_get_country_locale() { 
  750. if ( function_exists('WC') ) : 
  751. return WC()->countries->get_country_locale(); 
  752. else : 
  753. global $woocommerce; 
  754. return $woocommerce->countries->get_country_locale(); 
  755. endif; 
  756.  
  757. /** 
  758. * Helper function: not really necessary... 
  759. * @access public 
  760. * @since 1.7.1 
  761. * @return array of allowed countries 
  762. */ 
  763. public function wcpgsk_get_allowed_countries() { 
  764. if ( function_exists('WC') ) : 
  765. return WC()->countries->get_allowed_countries(); 
  766. else : 
  767. global $woocommerce; 
  768. return $woocommerce->countries->get_allowed_countries(); 
  769. endif; 
  770.  
  771. /** 
  772. * Locale field form 
  773. * @access public 
  774. * @since 1.7.1 
  775. * @echo html 
  776. */  
  777. public function get_locale_field_form_callback() { 
  778. $jsfields = $this->wcpgsk_get_country_locale_field_selectors(); //WC()->countries->get_country_locale_field_selectors(); 
  779. $localedata = $this->wcpgsk_get_country_locale(); //WC()->countries->get_country_locale(); 
  780. $locale = get_option('wcpgsk_locale'); 
  781. $localeCode = $_POST['localeCode']; 
  782.  
  783. if ( $localeCode ) : 
  784. ?> 
  785. <tr> 
  786. <td colspan="3"> 
  787. <input name="wcpgsk_settings[locale][countrycode]" type="hidden" value="<?php echo $localeCode; ?>" /> 
  788. </td> 
  789. </tr> 
  790. <?php 
  791. $localepostcode = isset($localedata[$localeCode]) && isset($localedata[$localeCode]['postcode_before_city']) ? ( $localedata[$localeCode]['postcode_before_city'] ? '1' : '0' ) : ( isset($localedata['default']['postcode_before_city']) && $localedata['default']['postcode_before_city'] ? '1' : '0' ); 
  792. $locale[$localeCode]['postcode_before_city'] = isset($locale[$localeCode]['postcode_before_city']) ? $locale[$localeCode]['postcode_before_city'] : $localepostcode; 
  793. foreach ($jsfields as $field => $fieldids) : 
  794. $localelabel = isset($localedata[$localeCode]) && isset($localedata[$localeCode][$field]) && isset($localedata[$localeCode][$field]['label']) ? $localedata[$localeCode][$field]['label'] : ( isset($localedata['default'][$field]['label']) ? $localedata['default'][$field]['label'] : '' ); 
  795. $locale[$localeCode]['label_' . $field] = isset($locale[$localeCode]['label_' . $field]) ? $locale[$localeCode]['label_' . $field] : $localelabel; 
  796.  
  797. $localeplaceholder = isset($localedata[$localeCode]) && isset($localedata[$localeCode][$field]) && isset($localedata[$localeCode][$field]['placeholder']) ? $localedata[$localeCode][$field]['placeholder'] : ( isset($localedata['default'][$field]['placeholder']) ? $localedata['default'][$field]['placeholder'] : '' ); 
  798. $locale[$localeCode]['placeholder_' . $field] = isset($locale[$localeCode]['placeholder_' . $field]) ? $locale[$localeCode]['placeholder_' . $field] : $localeplaceholder; 
  799.  
  800. $localerequired = isset($localedata[$localeCode]) && isset($localedata[$localeCode][$field]) && isset($localedata[$localeCode][$field]['required']) ? ( $localedata[$localeCode][$field]['required'] ? '1' : '0' ) : ( isset($localedata['default'][$field]['required']) && $localedata['default'][$field]['required'] ? '1' : '0' ); 
  801. $locale[$localeCode]['required_' . $field] = isset($locale[$localeCode]['required_' . $field]) ? $locale[$localeCode]['required_' . $field] : $localerequired; 
  802. if ( $field !== 'state' ) : 
  803. $localehidden = isset($localedata[$localeCode]) && isset($localedata[$localeCode][$field]) && isset($localedata[$localeCode][$field]['hidden']) ? ( $localedata[$localeCode][$field]['hidden'] ? '1' : '0' ) : ( isset($localedata['default'][$field]['hidden']) && $localedata['default'][$field]['hidden'] ? '1' : '0' ); 
  804. $locale[$localeCode]['hidden_' . $field] = isset($locale[$localeCode]['hidden_' . $field]) ? $locale[$localeCode]['hidden_' . $field] : $localehidden; 
  805. endif; 
  806.  
  807.  
  808. ?> 
  809. <tr> 
  810. <td><?php echo $field; ?></td> 
  811. <td> 
  812. <input name="wcpgsk_settings[locale][required_<?php echo $field; ?>]" type="hidden" value="0" /> 
  813. <input name="wcpgsk_settings[locale][required_<?php echo $field; ?>]" type="checkbox" value="1" <?php if ( isset($locale[$localeCode]['required_' . $field]) && 1 == ($locale[$localeCode]['required_' . $field])) echo "checked='checked'"; ?> /> 
  814. </td> 
  815. <td> 
  816. <span class="description"><?php echo __('Required status for ', WCPGSK_DOMAIN) . ' ' . $field; ?></span> 
  817. </td> 
  818. </tr> 
  819. <?php if ( $field != 'state' ) : ?> 
  820. <tr> 
  821. <td><?php echo $field; ?></td> 
  822. <td> 
  823. <input name="wcpgsk_settings[locale][hidden_<?php echo $field; ?>]" type="hidden" value="0" /> 
  824. <input name="wcpgsk_settings[locale][hidden_<?php echo $field; ?>]" type="checkbox" value="1" <?php if ( isset($locale[$localeCode]['hidden_' . $field]) && 1 == ($locale[$localeCode]['hidden_' . $field])) echo "checked='checked'"; ?> /> 
  825. </td> 
  826. <td> 
  827. <span class="description"><?php echo __('Hidden status for ', WCPGSK_DOMAIN) . ' ' . $field; ?></span> 
  828. </td> 
  829. </tr> 
  830. <?php endif; ?> 
  831. <tr> 
  832. <td><?php echo $field; ?></td> 
  833. <td> 
  834. <input name="wcpgsk_settings[locale][label_<?php echo $field; ?>]" value="<?php if (isset($locale[$localeCode]['label_' . $field]) ) echo $locale[$localeCode]['label_' . $field]; ?>" class="regular-text" /> 
  835. </td> 
  836. <td> 
  837. <span class="description"><?php echo __('Label for ', WCPGSK_DOMAIN) . ' ' . $field; ?></span> 
  838. </td> 
  839. </tr> 
  840. <tr> 
  841. <td><?php echo $field; ?></td> 
  842. <td> 
  843. <input name="wcpgsk_settings[locale][placeholder_<?php echo $field; ?>]" value="<?php if (isset($locale[$localeCode]['placeholder_' . $field]) ) echo $locale[$localeCode]['placeholder_' . $field]; ?>" class="regular-text" /> 
  844. </td> 
  845. <td> 
  846. <span class="description"><?php echo __('Placeholder for ', WCPGSK_DOMAIN) . ' ' . $field; ?></span> 
  847. </td> 
  848. </tr> 
  849. <tr> 
  850. <td colspan="3"><hr /></td> 
  851. </tr> 
  852. <?php 
  853. endforeach; 
  854. ?> 
  855. <tr> 
  856. <td><?php echo __('Post/Zip Code Placement', WCPGSK_DOMAIN); ?></td> 
  857. <td> 
  858. <input name="wcpgsk_settings[locale][postcode_before_city]" type="hidden" value="0" /> 
  859. <input name="wcpgsk_settings[locale][postcode_before_city]" type="checkbox" value="1" <?php if ( isset($locale[$localeCode]['postcode_before_city']) && 1 == ($locale[$localeCode]['postcode_before_city'])) echo "checked='checked'"; ?> /> 
  860. </td> 
  861. <td> 
  862. <span class="description"><?php echo __('Post/Zip code before city', WCPGSK_DOMAIN); ?></span> 
  863. </td> 
  864. </tr> 
  865.  
  866. <?php 
  867. endif; 
  868.  
  869. /** 
  870. * Product Tab Content for Min/Max/Step Configuration for Simple and Variable products 
  871. * @access public 
  872. * @since 1.6.0 
  873. * @echo html 
  874. */ 
  875. public function wcpgsk_product_write_panels() { 
  876. global $post; 
  877. $options = get_option( 'wcpgsk_settings' ); 
  878. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) : 
  879.  
  880. // the product 
  881. if ( $terms = wp_get_object_terms( $post->ID, 'product_type' ) ) 
  882. $product_type = sanitize_title( current( $terms )->name ); 
  883. else 
  884. $product_type = 'simple'; 
  885. if ( $product_type === 'simple' || $product_type === 'variable' ) :  
  886. /** 
  887. $minqty = get_post_meta( $post->ID, '_wcpgsk_minqty', true ); 
  888. $maxqty = get_post_meta( $post->ID, '_wcpgsk_maxqty', true ); 
  889. $stepqty = get_post_meta( $post->ID, '_wcpgsk_stepqty', true ); 
  890. $minqty = isset($minqty) && !empty($minqty) ? $minqty : 0; 
  891. $maxqty = isset($maxqty) && !empty($maxqty) ? $maxqty : 0; 
  892. $stepqty = isset($stepqty) && !empty($stepqty) ? $stepqty : 0; 
  893. */ 
  894. $style = 'width:125px;padding:5px 5px 5px 5px;font-size:inherit !important;font-family:inherit !important;font-face:inherit !important;line-height: 18px !important;'; 
  895. $style_before = 'height:auto !important;vertical-align:sub;padding: 0 3px 0 0 !important;font:400 20px/1 dashicons !important;line-height: 18px !important;content:"\f163";'; 
  896. $active_style = '';  
  897. ?> 
  898. <style type="text/css"> 
  899. #woocommerce-product-data ul.product_data_tabs li.wcpgsk_product_tab a { <?php echo $style; ?> } 
  900. #woocommerce-product-data ul.product_data_tabs li.wcpgsk_product_tab a:hover { <?php echo $style; ?> } 
  901. #woocommerce-product-data ul.product_data_tabs li.wcpgsk_product_tab a:before { <?php echo $style_before; ?> } 
  902. <?php echo $active_style; ?> 
  903. </style> 
  904. <div id="wcpgsk_data_tab" class="panel wc-metaboxes-wrapper woocommerce_options_panel"> 
  905. <?php 
  906. do_action( 'wcpgsk_qty_panel_settings' ); 
  907. woocommerce_wp_checkbox( array( 'id' => '_wcpgsk_selectqty', 'label' => __( 'Quantity Selector', WCPGSK_DOMAIN ), 'description' => __( 'Convert quantity input to selector based on quantity configuration.', WCPGSK_DOMAIN ) ) ); 
  908.  
  909. woocommerce_wp_text_input( array( 'id' => '_wcpgsk_minqty', 'type' => 'numeric', 'label' => __( 'Minimum Quantity', WCPGSK_DOMAIN ), 'desc_tip' => true, 'description' => __( 'Please specify an integer value. 0 deactivates the option.', WCPGSK_DOMAIN ), 'custom_attributes' => array('style' => 'width:40%' ) ) ); 
  910. woocommerce_wp_text_input( array( 'id' => '_wcpgsk_maxqty', 'type' => 'numeric', 'label' => __( 'Maximum Quantity', WCPGSK_DOMAIN ), 'desc_tip' => true, 'description' => __( 'Please specify an integer value. Should be equal or higher than minimum value or 0. 0 deactivates the option.', WCPGSK_DOMAIN ), 'custom_attributes' => array('style' => 'width:40%' ) ) ); 
  911. woocommerce_wp_text_input( array( 'id' => '_wcpgsk_stepqty', 'type' => 'numeric', 'label' => __( 'Increment Quantity', WCPGSK_DOMAIN ), 'desc_tip' => true, 'description' => __( 'Please specify an integer value for increment steps. Please assure consistency with minimum and maximum value. 0 deactivates the option.', WCPGSK_DOMAIN ), 'custom_attributes' => array('style' => 'width:40%' ) ) ); 
  912. ?> 
  913. </div> 
  914. <?php 
  915. endif; 
  916. endif; 
  917.  
  918. /** 
  919. * Store WCPGSK Min/Max/Step configuration data for the product 
  920. * @access public 
  921. * @since 1.6.0 
  922. * @return void 
  923. */ 
  924. public function wcpgsk_process_product_meta( $post_id ) { 
  925. global $woocommerce, $wpdb; 
  926. $options = get_option( 'wcpgsk_settings' ); 
  927. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) : 
  928.  
  929. if (WP_DEBUG) { 
  930. //trigger_error(sprintf(__("The 'label' and 'id' values of the 'args' parameter of '%s::%s()' are required", WCPGSK_DOMAIN), $_POST['_wcpgsk_minqty'], $post_id)); 
  931. //die(); 
  932. $minqty = 0; 
  933. $maxqty = 0; 
  934. $stepqty = 0; 
  935. if ( isset( $_POST['_wcpgsk_minqty'] ) && is_numeric($_POST['_wcpgsk_minqty']) ) : 
  936. $minqty = intval($_POST['_wcpgsk_minqty']) ; 
  937. endif; 
  938. if ( isset( $_POST['_wcpgsk_maxqty'] ) && is_numeric($_POST['_wcpgsk_maxqty']) ) : 
  939. $maxqty = intval($_POST['_wcpgsk_maxqty']) ; 
  940. endif; 
  941. if ( isset( $_POST['_wcpgsk_stepqty'] ) && is_numeric($_POST['_wcpgsk_stepqty']) ) : 
  942. $stepqty = intval($_POST['_wcpgsk_stepqty']) ; 
  943. endif; 
  944.  
  945. if ($minqty > $maxqty && $maxqty > 0) $minqty = 1; 
  946. if ($maxqty < $minqty) $maxqty = 0; 
  947. do_action( 'wcpgsk_process_additional_product_meta', $post_id ); 
  948. if ( isset( $_POST['_wcpgsk_selectqty'] ) && $_POST['_wcpgsk_selectqty'] == 'yes' ) : 
  949. update_post_meta( $post_id, '_wcpgsk_selectqty', 'yes' ); 
  950. else : 
  951. update_post_meta( $post_id, '_wcpgsk_selectqty', 0 ); 
  952. endif; 
  953. update_post_meta( $post_id, '_wcpgsk_minqty', $minqty ); 
  954. update_post_meta( $post_id, '_wcpgsk_maxqty', $maxqty ); 
  955. update_post_meta( $post_id, '_wcpgsk_stepqty', $stepqty ); 
  956. endif; 
  957. if ( isset( $_POST['_wcpgsk_button_label'] ) && $_POST['_wcpgsk_button_label'] ) : 
  958. update_post_meta( $post_id, '_wcpgsk_button_label', wp_kses_post( $_POST['_wcpgsk_button_label'] ) ); 
  959. else : 
  960. update_post_meta( $post_id, '_wcpgsk_button_label', '' ); 
  961. endif; 
  962. if ( isset( $_POST['_wcpgsk_extend_price'] ) && $_POST['_wcpgsk_extend_price'] ) : 
  963. update_post_meta( $post_id, '_wcpgsk_extend_price', wp_kses_post( $_POST['_wcpgsk_extend_price'] ) ); 
  964. update_post_meta( $post_id, '_wcpgsk_extend_price_placement', $_POST['_wcpgsk_extend_price_placement'] );  
  965. else : 
  966. update_post_meta( $post_id, '_wcpgsk_extend_price', '' ); 
  967. update_post_meta( $post_id, '_wcpgsk_extend_price_placement', 'after' );  
  968. endif; 
  969. if ( isset( $_POST['_wcpgsk_empty_price_html'] ) && $_POST['_wcpgsk_empty_price_html'] ) : 
  970. update_post_meta( $post_id, '_wcpgsk_empty_price_html', wp_kses_post( $_POST['_wcpgsk_empty_price_html'] ) );  
  971. else : 
  972. update_post_meta( $post_id, '_wcpgsk_empty_price_html', '' );  
  973. endif; 
  974. if ( isset( $_POST['_wcpgsk_free_sale_html'] ) && $_POST['_wcpgsk_free_sale_html'] ) : 
  975. update_post_meta( $post_id, '_wcpgsk_free_sale_html', wp_kses_post( $_POST['_wcpgsk_free_sale_html'] ) );  
  976. else : 
  977. update_post_meta( $post_id, '_wcpgsk_free_sale_html', '' );  
  978. endif; 
  979. if ( isset( $_POST['_wcpgsk_free_price_html'] ) && $_POST['_wcpgsk_free_price_html'] ) : 
  980. update_post_meta( $post_id, '_wcpgsk_free_price_html', wp_kses_post( $_POST['_wcpgsk_free_price_html'] ) );  
  981. else : 
  982. update_post_meta( $post_id, '_wcpgsk_free_price_html', '' );  
  983. endif; 
  984. if ( isset( $_POST['_wcpgsk_onsale_html'] ) && $_POST['_wcpgsk_onsale_html'] ) : 
  985. update_post_meta( $post_id, '_wcpgsk_onsale_html', wp_kses_post( $_POST['_wcpgsk_onsale_html'] ) );  
  986. else : 
  987. update_post_meta( $post_id, '_wcpgsk_onsale_html', '' );  
  988. endif; 
  989.  
  990.  
  991. /** 
  992. * Check for minimum and maximum items in cart and if they fulfill the settings. 
  993. * and raise error and message if rules are not fulfilled, otherwise clear messages 
  994. * @access public 
  995. * @param mixed $checkout 
  996. * @since 1.1.0 
  997. * @return void 
  998. */  
  999. public function wcpgsk_checkout_init($checkout) { 
  1000. global $woocommerce; 
  1001. $options = get_option( 'wcpgsk_settings' ); 
  1002.  
  1003. $cartItems = sizeof( $woocommerce->cart->cart_contents ); 
  1004. $allowed = $options['cart']['maxitemscart']; 
  1005.  
  1006. //check cart items count and diminish if more than one variation for a product exists 
  1007. if ($allowed > 0 && isset($options['cart']['variationscountasproduct']) && $options['cart']['variationscountasproduct'] == 0) {  
  1008. $varproducts = array(); 
  1009. foreach($woocommerce->cart->cart_contents as $i => $values) { 
  1010. $key = $values['product_id']; 
  1011. if (isset($values[$key]) && isset($values[$variation_id]) && $values[$key] != $values['variation_id']) { 
  1012. if (isset($varproducts[$key])) $varproducts[$key] = 1; 
  1013. else $varproducts[$key] = 0; 
  1014. if (!empty($varproducts)) $cartItems = $cartItems - array_sum($varproducts); 
  1015.  
  1016. if ($allowed > 0 && $cartItems > $allowed ) : 
  1017. wcpgsk_clear_messages(); 
  1018. // Sets error message. 
  1019. wcpgsk_add_error( sprintf( __( 'You have reached the maximum amount of %s items allowed for your cart!', WCPGSK_DOMAIN ), $allowed ) ); 
  1020. wcpgsk_set_messages(); 
  1021. $cart_url = $woocommerce->cart->get_cart_url(); 
  1022. wcpgsk_add_message( __('Remove products from the cart', WCPGSK_DOMAIN) . ': <a href="' . $cart_url . '">' . __('Cart', WCPGSK_DOMAIN) . '</a>'); 
  1023. wcpgsk_set_messages(); 
  1024. //wp_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) ); 
  1025. //exit;  
  1026. else : 
  1027. $allowed = $options['cart']['minitemscart']; 
  1028.  
  1029. //check cart items count and diminish if more than one variation for a product exists 
  1030. if ($allowed > 1 && isset($options['cart']['variationscountasproduct']) && $options['cart']['variationscountasproduct'] == 0) {  
  1031. $varproducts = array(); 
  1032. foreach($woocommerce->cart->cart_contents as $i => $values) { 
  1033. $key = $values['product_id']; 
  1034. if (isset($values[$key]) && isset($values['variation_id']) && $values[$key] != $values['variation_id']) { 
  1035. if (isset($varproducts[$key])) $varproducts[$key] = 1; 
  1036. else $varproducts[$key] = 0; 
  1037. if (!empty($varproducts)) $cartItems = $cartItems - array_sum($varproducts); 
  1038.  
  1039. if ($allowed > 1 && $allowed > $cartItems ) : 
  1040. // Sets error message. 
  1041. wcpgsk_clear_messages(); 
  1042.  
  1043. wcpgsk_add_error( sprintf( __( 'You still have not reached the minimum amount of %s items required for your cart!', WCPGSK_DOMAIN ), $allowed ) ); 
  1044. wcpgsk_set_messages(); 
  1045. $valid = false; 
  1046.  
  1047. $shop_page_id = woocommerce_get_page_id( 'shop' ); 
  1048. //$shop_page_url = get_permalink(icl_object_id($shop_page_id, 'page', false)); 
  1049. $shop_page_url = get_permalink($shop_page_id); 
  1050. wcpgsk_add_message( __('Select more products from the shop', WCPGSK_DOMAIN) . ': <a href="' . $shop_page_url . '">' . __('Shop', WCPGSK_DOMAIN) . '</a>'); 
  1051. wcpgsk_set_messages(); 
  1052. //wp_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) ); 
  1053. //exit;  
  1054. else : 
  1055. wcpgsk_clear_messages();  
  1056. endif; 
  1057. endif; 
  1058.  
  1059. /** 
  1060. * Register settings. 
  1061. * Establish settings if no default settings are available for some resason 
  1062. * @access public 
  1063. * @since 1.1.0 
  1064. * @return void 
  1065. */  
  1066. public function wcpgsk_register_setting() {  
  1067. register_setting( 'wcpgsk_options', 'wcpgsk_settings', array($this, 'wcpgsk_options_validate') ); 
  1068. //check if we have initial settings, if not store default settings 
  1069. global $wcpgsk_options; 
  1070. $this->register_plugin_version(); 
  1071. $wcpgsk_options = get_option( 'wcpgsk_settings' ); 
  1072. if ( empty($wcpgsk_options) ) : 
  1073. $this->wcpgsk_initial_settings(); 
  1074. endif; 
  1075.  
  1076. public function wcpgsk_load_order_data($meta) { 
  1077. global $woocommerce; 
  1078. $options = get_option( 'wcpgsk_settings' ); 
  1079. $metas = array(); 
  1080. $checkout_fields = array_merge($woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), 'billing_' ), $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), 'shipping_' )); 
  1081. //$meta = array_merge($meta, $checkout_fields); 
  1082. foreach ($checkout_fields as $key => $field) :  
  1083. if ( isset($options['woofields']['billing'][$key]['custom_' . $key]) && $options['woofields']['billing'][$key]['custom_' . $key] && !isset($meta[$key]) ) : 
  1084. $meta[$key] = ''; 
  1085. elseif ( isset($options['woofields']['shipping'][$key]['custom_' . $key]) && $options['woofields']['shipping'][$key]['custom_' . $key] && !isset($meta[$key]) ) :  
  1086. $meta[$key] = ''; 
  1087. endif;  
  1088. endforeach; 
  1089.  
  1090. return apply_filters( 'wcpgsk_load_order_data', $meta );  
  1091.  
  1092. /** 
  1093. * Display billing and shipping form data captured. 
  1094. * @access public 
  1095. * @since 1.3.0 
  1096. * @output html 
  1097. */  
  1098. public function wcpgsk_email_after_order_table($order) { 
  1099. if ( !isset( $order->hidecustomproductemail ) || $order->hidecustomproductemail != 'yes' ) : 
  1100. global $woocommerce; 
  1101. $options = get_option( 'wcpgsk_settings' ); 
  1102. $billing_fields = $this->wcpgsk_additional_data($order, 'billing'); 
  1103. $shipping_fields = $this->wcpgsk_additional_data($order, 'shipping'); 
  1104. ?> 
  1105. <table cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0" class="wcpgsk_customer_data"> 
  1106.  
  1107. <tr> 
  1108. <?php  
  1109. if ( isset($billing_fields) && !empty($billing_fields) ) :  
  1110. ?> 
  1111. <td valign="top" width="50%" class="billing_data"> 
  1112.  
  1113. <?php if ( !empty($options['checkoutform']['morebillingtitle']) ) : ?> 
  1114. <h3><?php _e( $options['checkoutform']['morebillingtitle'], 'woocommerce' ); ?></h3> 
  1115. <?php endif; ?> 
  1116.  
  1117. <dl> 
  1118. <?php  
  1119. foreach ($billing_fields as $key => $field) : 
  1120. $key_type = "billing_" . $key; 
  1121. $label = !empty($field['label']) ? $field['label'] . ": " : ""; 
  1122. if ( is_array( $field['captured'] ) ) : 
  1123. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( implode( '<br />', $field['captured'] ) ) ) . '</dd>'; 
  1124. else : 
  1125. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( $field['captured'] ) ) . '</dd>'; 
  1126. endif; 
  1127. endforeach; 
  1128. ?> 
  1129. </dl> 
  1130.  
  1131. </td> 
  1132.  
  1133. <?php  
  1134. endif; 
  1135. if ( get_option( 'woocommerce_ship_to_billing_address_only' ) == 'no' && isset($shipping_fields) && !empty($shipping_fields) ) :  
  1136. ?> 
  1137.  
  1138. <td valign="top" width="50%" class="shipping_data"> 
  1139. <?php if ( !empty($options['checkoutform']['moreshippingtitle']) ) : ?> 
  1140. <h3><?php _e( $options['checkoutform']['moreshippingtitle'], 'woocommerce' ); ?></h3> 
  1141. <?php endif; ?> 
  1142.  
  1143. <dl> 
  1144. <?php  
  1145. foreach ($shipping_fields as $key => $field) : 
  1146. $key_type = "shipping_" . $key; 
  1147. $label = !empty($field['label']) ? $field['label'] . ": " : ""; 
  1148. if ( is_array( $field['captured'] ) ) : 
  1149. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( implode( '<br />', $field['captured'] ) ) ) . '</dd>'; 
  1150. else : 
  1151. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( $field['captured'] ) ) . '</dd>'; 
  1152. endif; 
  1153. endforeach; 
  1154. ?> 
  1155. </dl> 
  1156.  
  1157. </td> 
  1158.  
  1159. <?php endif; ?> 
  1160.  
  1161. </tr> 
  1162.  
  1163. </table> 
  1164. <?php 
  1165. endif; 
  1166.  
  1167. /** 
  1168. * Display billing and shipping form data captured. 
  1169. * @access public 
  1170. * @since 1.3.0 
  1171. * @output html 
  1172. */  
  1173. public function wcpgsk_order_details_after_order_table($order) { 
  1174. $options = get_option( 'wcpgsk_settings' ); 
  1175. $billing_fields = $this->wcpgsk_additional_data($order, 'billing'); 
  1176. $shipping_fields = $this->wcpgsk_additional_data($order, 'shipping'); 
  1177. ?> 
  1178. <table cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top;" border="0"> 
  1179. <tr> 
  1180. <?php  
  1181. if ( isset($billing_fields) && !empty($billing_fields) ) :  
  1182. ?> 
  1183. <td valign="top" width="50%" class="billing_data"> 
  1184.  
  1185. <?php if ( !empty($options['checkoutform']['morebillingtitle']) ) : ?> 
  1186. <h3><?php _e( $options['checkoutform']['morebillingtitle'], 'woocommerce' ); ?></h3> 
  1187. <?php endif; ?> 
  1188.  
  1189. <dl> 
  1190. <?php  
  1191. //$billing_fields = $this->wcpgsk_additional_data($order, 'billing'); 
  1192. //if ( isset($billing_fields) && !empty($billing_fields) ) : 
  1193. foreach ($billing_fields as $key => $field) : 
  1194. $key_type = "billing_" . $key; 
  1195. $label = !empty($field['label']) ? $field['label'] . ": " : ""; 
  1196. if ( is_array( $field['captured'] ) ) : 
  1197. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( implode( '<br />', $field['captured'] ) ) ) . '</dd>'; 
  1198. else : 
  1199. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( $field['captured'] ) ) . '</dd>'; 
  1200. endif; 
  1201. endforeach; 
  1202. //endif; 
  1203. ?> 
  1204. </dl> 
  1205.  
  1206. </td> 
  1207.  
  1208. <?php  
  1209. endif; 
  1210. if ( get_option( 'woocommerce_ship_to_billing_address_only' ) == 'no' && isset($shipping_fields) && !empty($shipping_fields) ) :  
  1211. ?> 
  1212.  
  1213. <td valign="top" width="50%" class="shipping_data"> 
  1214. <?php if ( !empty($options['checkoutform']['moreshippingtitle']) ) : ?> 
  1215. <h3><?php _e( $options['checkoutform']['moreshippingtitle'], 'woocommerce' ); ?></h3> 
  1216. <?php endif; ?> 
  1217. <dl> 
  1218. <?php  
  1219. foreach ($shipping_fields as $key => $field) : 
  1220. $key_type = "shipping_" . $key; 
  1221. $label = !empty($field['label']) ? $field['label'] . ": " : ""; 
  1222. if ( is_array( $field['captured'] ) ) : 
  1223. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( implode( '<br />', $field['captured'] ) ) ) . '</dd>'; 
  1224. else : 
  1225. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( $field['captured'] ) ) . '</dd>'; 
  1226. endif; 
  1227. endforeach; 
  1228. ?> 
  1229. </dl> 
  1230.  
  1231. </td> 
  1232.  
  1233. <?php endif; ?> 
  1234.  
  1235. </tr> 
  1236.  
  1237. </table> 
  1238. <?php 
  1239.  
  1240. /** 
  1241. * Display billing and shipping custom fields for user meta on my-account page. 
  1242. * @access public 
  1243. * @since 2.1.2 
  1244. * @output html 
  1245. */  
  1246. public function wcpgsk_after_my_account() { 
  1247. $options = get_option( 'wcpgsk_settings' ); 
  1248. $billing_fields = $this->wcpgsk_additional_data_user('billing'); 
  1249. $shipping_fields = $this->wcpgsk_additional_data_user('shipping'); 
  1250. $col = 1; 
  1251.  
  1252. if ( get_option( 'woocommerce_ship_to_billing_address_only' ) == 'no' && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) echo '<div class="col2-set addresses">';  
  1253. ?> 
  1254. <div class="col-<?php echo ( ( $col = $col * -1 ) < 0 ) ? 1 : 2; ?> address billing_data"> 
  1255.  
  1256. <?php  
  1257. if ( isset($billing_fields) && !empty($billing_fields) ) :  
  1258. ?> 
  1259.  
  1260. <?php if ( !empty($options['checkoutform']['morebillingtitle']) ) : ?> 
  1261. <h3><?php _e( $options['checkoutform']['morebillingtitle'], 'woocommerce' ); ?></h3> 
  1262. <?php endif; ?> 
  1263.  
  1264. <dl> 
  1265. <?php  
  1266. //$billing_fields = $this->wcpgsk_additional_data($order, 'billing'); 
  1267. //if ( isset($billing_fields) && !empty($billing_fields) ) : 
  1268. foreach ($billing_fields as $key => $field) : 
  1269. $key_type = "billing_" . $key; 
  1270. $label = !empty($field['label']) ? $field['label'] . ": " : ""; 
  1271. if ( is_array( $field['captured'] ) ) : 
  1272. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( implode( '<br />', $field['captured'] ) ) ) . '</dd>'; 
  1273. else : 
  1274. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( $field['captured'] ) ) . '</dd>'; 
  1275. endif; 
  1276. endforeach; 
  1277. //endif; 
  1278. ?> 
  1279. </dl> 
  1280. </div> 
  1281. <?php  
  1282. endif; 
  1283. if ( get_option( 'woocommerce_ship_to_billing_address_only' ) == 'no' && isset($shipping_fields) && !empty($shipping_fields) ) :  
  1284.  
  1285. ?> 
  1286. <div class="col-<?php echo ( ( $col = $col * -1 ) < 0 ) ? 1 : 2; ?> address shipping_data"> 
  1287. <?php if ( !empty($options['checkoutform']['moreshippingtitle']) ) : ?> 
  1288. <h3><?php _e( $options['checkoutform']['moreshippingtitle'], 'woocommerce' ); ?></h3> 
  1289. <?php endif; ?> 
  1290. <dl> 
  1291. <?php  
  1292. foreach ($shipping_fields as $key => $field) : 
  1293. $key_type = "shipping_" . $key; 
  1294. $label = !empty($field['label']) ? $field['label'] . ": " : ""; 
  1295. if ( is_array( $field['captured'] ) ) : 
  1296. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( implode( '<br />', $field['captured'] ) ) ) . '</dd>'; 
  1297. else : 
  1298. echo '<dt>' . $label . '</dt><dd>' . wp_kses_post( make_clickable( $field['captured'] ) ) . '</dd>'; 
  1299. endif; 
  1300. endforeach; 
  1301. ?> 
  1302. </dl> 
  1303.  
  1304. </div> 
  1305.  
  1306. <?php endif; ?> 
  1307.  
  1308. <?php 
  1309. if ( get_option( 'woocommerce_ship_to_billing_address_only' ) == 'no' && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) echo '</div>'; 
  1310.  
  1311.  
  1312. /** 
  1313. * Update our order billing address. 
  1314. * @access public 
  1315. * @since 1.3.0 
  1316. * @output Settings page 
  1317. */  
  1318. public function wcpgsk_additional_data($order, $fortype) { 
  1319. global $woocommerce; 
  1320. $options = get_option( 'wcpgsk_settings' ); 
  1321. $captured_fields = array(); 
  1322. $field_order = 1;  
  1323. $checkout_fields = $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), $fortype . '_' ); 
  1324. foreach ($checkout_fields as $key => $field) : 
  1325. $checkout_fields[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order); 
  1326. $checkout_fields[$key]['required'] = ((isset($options['woofields']['required_' . $key])) ? $options['woofields']['required_' . $key] : $checkout_fields[$key]['required']); 
  1327. $checkout_fields[$key]['hideorder'] = ((isset($options['woofields']['hideorder_' . $key])) ? $options['woofields']['hideorder_' . $key] : 0); 
  1328. if (!isset($configField['label'])) $configField['label'] = __($checkout_fields[$key]['label'], WCPGSK_DOMAIN);  
  1329. $field_order++; 
  1330. endforeach; 
  1331.  
  1332. uasort($checkout_fields, array($this, "compareFieldOrder"));  
  1333.  
  1334. foreach ($checkout_fields as $key => $field) :  
  1335. //$fieldLabel = $field['displaylabel']; 
  1336. $fieldkey = str_replace('billing_', '', $key); 
  1337. $fieldkey = str_replace('shipping_', '', $key); 
  1338.  
  1339. if ($key != 'billing_email_validator' && $field['hideorder'] == 0 && $key != 'billing_phone' && $key != 'billing_email' && !$field['hideorder'] ) : 
  1340. if ( isset($options['woofields'][$fortype][$key]['custom_' . $key]) && $options['woofields'][$fortype][$key]['custom_' . $key]) : 
  1341. $configField['label'] = isset($checkout_fields[$key]['label']) && !empty($checkout_fields[$key]['label']) ? __($checkout_fields[$key]['label'], WCPGSK_DOMAIN) : ""; 
  1342. $captured_value = $order->$key; 
  1343. if ( isset($options['woofields']['settings_' . $key]) ) : 
  1344. $params = $this->explodeParameters($options['woofields']['settings_' . $key]); 
  1345. if ( isset($params) && isset($params['validate']) && !empty($params['validate']) && $params['validate'] == 'password' ) : 
  1346. $captured_value = '*******'; 
  1347. endif; 
  1348. endif; 
  1349. $configField['captured'] = $captured_value; 
  1350. $captured_fields[$fieldkey] = $configField; 
  1351. endif; 
  1352. endif; 
  1353. endforeach; 
  1354. return $captured_fields;  
  1355.  
  1356. /** 
  1357. * Get user meta data for billing or shipping. 
  1358. * @access public 
  1359. * @since 2.1.2 
  1360. * @output Settings page 
  1361. */  
  1362. public function wcpgsk_additional_data_user($fortype) { 
  1363. global $woocommerce; 
  1364. $customer_id = get_current_user_id(); 
  1365. $options = get_option( 'wcpgsk_settings' ); 
  1366. $captured_fields = array(); 
  1367. $field_order = 1;  
  1368. $checkout_fields = $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), $fortype . '_' ); 
  1369. foreach ($checkout_fields as $key => $field) : 
  1370. $checkout_fields[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order); 
  1371. $checkout_fields[$key]['required'] = ((isset($options['woofields']['required_' . $key])) ? $options['woofields']['required_' . $key] : $checkout_fields[$key]['required']); 
  1372. $checkout_fields[$key]['hideorder'] = ((isset($options['woofields']['hideorder_' . $key])) ? $options['woofields']['hideorder_' . $key] : 0); 
  1373. if (!isset($configField['label'])) $configField['label'] = __($checkout_fields[$key]['label'], WCPGSK_DOMAIN);  
  1374. $field_order++; 
  1375. endforeach; 
  1376.  
  1377. uasort($checkout_fields, array($this, "compareFieldOrder"));  
  1378.  
  1379. foreach ($checkout_fields as $key => $field) :  
  1380. //$fieldLabel = $field['displaylabel']; 
  1381. $fieldkey = str_replace('billing_', '', $key); 
  1382. $fieldkey = str_replace('shipping_', '', $key); 
  1383. if ($key != 'billing_email_validator' && $key != 'billing_phone' && $key != 'billing_email' ) : 
  1384. if ( isset($options['woofields'][$fortype][$key]['custom_' . $key]) && $options['woofields'][$fortype][$key]['custom_' . $key]) : 
  1385. $configField['label'] = isset($checkout_fields[$key]['label']) && !empty($checkout_fields[$key]['label']) ? __($checkout_fields[$key]['label'], WCPGSK_DOMAIN) : ""; 
  1386. $captured_value = get_user_meta( $customer_id, $key, true );//$order->$key; 
  1387. if ( isset($options['woofields']['settings_' . $key]) ) : 
  1388. $params = $this->explodeParameters($options['woofields']['settings_' . $key]); 
  1389. if ( isset($params) && isset($params['validate']) && !empty($params['validate']) && $params['validate'] == 'password' ) : 
  1390. $captured_value = '*******'; 
  1391. endif; 
  1392. endif; 
  1393. $configField['captured'] = $captured_value; 
  1394. $captured_fields[$fieldkey] = $configField; 
  1395. endif; 
  1396. endif; 
  1397. endforeach; 
  1398. return $captured_fields;  
  1399.  
  1400. /** 
  1401. * Our Admin Settings Page. 
  1402. * @access public 
  1403. * @since 1.1.0 
  1404. * @output Settings page 
  1405. */  
  1406. public function wcpgsk__options_page() { 
  1407. global $woocommerce, $wcpgsk_options, $wcpgsk_name; 
  1408. //must check that the user has the required capability  
  1409. if (!current_user_can('manage_options')) 
  1410. wp_die( __('You do not have sufficient permissions to access this page.') ); 
  1411. $hidden_field_name = 'wcpgsk_submit_hidden'; 
  1412. // read options values 
  1413. $options = get_option( 'wcpgsk_settings' ); 
  1414. if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) { 
  1415. // Save the posted values in the database 
  1416. //var_dump($_POST); 
  1417. /** 
  1418. if ( isset($_POST['wcpgsk_settings']['checkoutform']['checkoutjs']) ) : 
  1419. $wcpgsk_checkoutjs = $options['checkoutform']['checkoutjs']; 
  1420. $options['checkoutform']['checkoutjs'] = ''; 
  1421. update_option('wcpgsk_checkoutjs', $wcpgsk_checkoutjs); 
  1422. endif; 
  1423. */ 
  1424. update_option( 'wcpgsk_settings', $options ); 
  1425. //echo "<h1>mumpits</h1>"; 
  1426. do_action( 'wcpgsk_settings_update', $options ); 
  1427. // Now display the settings editing screen 
  1428. //get some reused labels 
  1429.  
  1430. $placeWide = __('Wide', WCPGSK_DOMAIN); 
  1431. $placeFirst = __('First', WCPGSK_DOMAIN); 
  1432. $placeLast = __('Last', WCPGSK_DOMAIN); 
  1433. $defchecked = __('Default: checked', WCPGSK_DOMAIN); 
  1434. $defunchecked = __('Default: unchecked', WCPGSK_DOMAIN); 
  1435.  
  1436.  
  1437. echo '<div class="wrap">'; 
  1438. // icon for settings 
  1439. echo '<div id="icon-themes" class="icon32"><br></div>'; 
  1440. // header 
  1441. $wcpgsk_name = apply_filters('wcpgsk_plus_name', $wcpgsk_name); 
  1442. echo "<h2>" . __( $wcpgsk_name, WCPGSK_DOMAIN ) . "</h2>"; 
  1443. // settings form  
  1444.  
  1445. if ( isset($options['locale']['countrycode']) && $options['locale']['countrycode'] ) : 
  1446. $locale = get_option( 'wcpgsk_locale', array() ); 
  1447.  
  1448. $localeCode = $options['locale']['countrycode']; 
  1449. $jsfields = $this->wcpgsk_get_country_locale_field_selectors(); 
  1450. foreach ($jsfields as $field => $fieldids) : 
  1451. $locale[$localeCode]['label_' . $field] = $options['locale']['label_' . $field]; 
  1452. $locale[$localeCode]['placeholder_' . $field] = $options['locale']['placeholder_' . $field]; 
  1453. $locale[$localeCode]['required_' . $field] = $options['locale']['required_' . $field]; 
  1454. if ( $field !== 'state' ) : 
  1455. $locale[$localeCode]['hidden_' . $field] = $options['locale']['hidden_' . $field]; 
  1456. endif; 
  1457. endforeach; 
  1458. $locale[$localeCode]['postcode_before_city'] = $options['locale']['postcode_before_city'];  
  1459. // Save the posted values in the database 
  1460. update_option( 'wcpgsk_locale', $locale ); 
  1461. endif; 
  1462.  
  1463. ?> 
  1464. <form name="form" method="post" action="options.php" id="frm1"> 
  1465. <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y"> 
  1466. <?php 
  1467. settings_fields( 'wcpgsk_options' ); 
  1468. $options = get_option( 'wcpgsk_settings' ); 
  1469. $options['process']['fastcheckoutbtn'] = isset($options['process']['fastcheckoutbtn']) ? $options['process']['fastcheckoutbtn'] : ''; 
  1470. $options['process']['readmorebtn'] = isset($options['process']['readmorebtn']) ? $options['process']['readmorebtn'] : ''; 
  1471. $options['process']['buyproductbtn'] = isset($options['process']['buyproductbtn']) ? $options['process']['buyproductbtn'] : ''; 
  1472. $options['process']['viewproductsbtn'] = isset($options['process']['viewproductsbtn']) ? $options['process']['viewproductsbtn'] : ''; 
  1473. $options['process']['selectoptionsbtn'] = isset($options['process']['selectoptionsbtn']) ? $options['process']['selectoptionsbtn'] : ''; 
  1474. $options['process']['outofstockbtn'] = isset($options['process']['outofstockbtn']) ? $options['process']['outofstockbtn'] : '';  
  1475. if ( !isset( $options['process']['onsalelabel'] ) ) : 
  1476. $options['process']['onsalelabel'] = __( 'Sale!', WCPGSK_DOMAIN ); 
  1477. endif; 
  1478. if ( !isset( $options['process']['backorderlabel'] ) ) : 
  1479. $options['process']['backorderlabel'] = ''; 
  1480. endif; 
  1481. if ( !isset( $options['process']['emptycartlabel'] ) ) : 
  1482. $options['process']['emptycartlabel'] = __( 'Empty cart?', WCPGSK_DOMAIN ); 
  1483. endif; 
  1484. if ( !isset( $options['process']['confirmemptycart'] ) ) : 
  1485. $options['process']['confirmemptycart'] = __( 'Yes, empty cart', WCPGSK_DOMAIN ); 
  1486. endif; 
  1487. if ( !isset( $options['checkoutform']['cssclass'] ) ) : 
  1488. $options['cssclass']['cssclass'] = ''; 
  1489. endif; 
  1490.  
  1491.  
  1492. //add options if necessary 
  1493. //unset( $options['filters'] ); 
  1494. if ( !isset( $options['filters'] ) || empty( $options['filters'] ) ) : 
  1495. $options['filters'] = array( 
  1496. 'loop_shop_per_page' => get_option( 'posts_per_page' ),  
  1497. 'loop_shop_columns' => '4',  
  1498. 'woocommerce_product_thumbnails_columns' => '3',  
  1499. 'woocommerce_create_account_default_checked' => 0,  
  1500. 'woocommerce_product_description_tab_title' => __('Description', 'woocommerce'),  
  1501. 'woocommerce_product_description_heading' => __( 'Product Description', 'woocommerce' ),  
  1502. 'woocommerce_product_additional_information_tab_title' => __('Additional Information', 'woocommerce'),  
  1503. 'woocommerce_product_additional_information_heading' => __( 'Additional Information', 'woocommerce' ),  
  1504. 'woocommerce_checkout_must_be_logged_in_message' => __( 'You must be logged in to checkout.', 'woocommerce' ),  
  1505. 'woocommerce_checkout_login_message' => __( 'Returning customer?', 'woocommerce' ),  
  1506.  
  1507. 'woocommerce_checkout_coupon_message' => __( 'Have a coupon?', 'woocommerce' ),  
  1508. 'woocommerce_checkout_coupon_link_message' => __( 'Click here to enter your code', 'woocommerce' ),  
  1509.  
  1510. 'woocommerce_order_button_text' => __( 'Place order', 'woocommerce' ),  
  1511. 'woocommerce_pay_order_button_text' => __( 'Pay for order', 'woocommerce' ),  
  1512. 'woocommerce_thankyou_order_received_text' => __( 'Thank you. Your order has been received.', 'woocommerce' ),  
  1513.  
  1514. 'woocommerce_countries_tax_or_vat' => $this->WC()->countries->tax_or_vat(),  
  1515. 'woocommerce_countries_inc_tax_or_vat' => $this->WC()->countries->inc_tax_or_vat(),  
  1516. 'woocommerce_countries_ex_tax_or_vat' => $this->WC()->countries->ex_tax_or_vat(),  
  1517. 'woocommerce_placeholder_img_src' => '',  
  1518. ); 
  1519. endif; 
  1520.  
  1521. ?> 
  1522. <div id="wcpgsk_accordion"> 
  1523. <?php do_action( 'wcpgsk_settings_page_zero', $options ); ?> 
  1524.  
  1525. <h3 class="wcpgsk_acc_header"><?php echo __('Shop Settings', WCPGSK_DOMAIN); ?></h3> 
  1526. <div> 
  1527. <table class="widefat" border="1" > 
  1528. <thead> 
  1529. <tr> 
  1530. <th><?php _e('Settings Name', WCPGSK_DOMAIN); ?></th> 
  1531. <th><?php _e('Data', WCPGSK_DOMAIN); ?></th>  
  1532. <th><?php _e('Comments', WCPGSK_DOMAIN); ?></th> 
  1533. </tr> 
  1534. </thead> 
  1535. <tbody> 
  1536. <tr> 
  1537. <td><?php _e('Product items per page', WCPGSK_DOMAIN); ?>:</td> 
  1538. <td> 
  1539. <input name="wcpgsk_settings[filters][loop_shop_per_page]" type="number" value="<?php if (isset($options['filters']['loop_shop_per_page'])) echo esc_attr( $options['filters']['loop_shop_per_page'] ); ?>" size="3" class="regular-text" /> 
  1540. </td> 
  1541. <td> 
  1542. <span class="description"><?php esc_attr(_e('Specify the number of items you want to show on a shop page.', WCPGSK_DOMAIN)); ?></span> 
  1543. </td> 
  1544. </tr> 
  1545. <tr> 
  1546. <td><?php _e('Product columns per page', WCPGSK_DOMAIN); ?>:</td> 
  1547. <td> 
  1548. <input name="wcpgsk_settings[filters][loop_shop_columns]" type="number" value="<?php if (isset($options['filters']['loop_shop_columns'])) echo esc_attr( $options['filters']['loop_shop_columns'] ); ?>" size="2" class="regular-text" /> 
  1549. </td> 
  1550. <td> 
  1551. <span class="description"><?php esc_attr(_e('Specify the number of product columns you want to show on a shop page.', WCPGSK_DOMAIN)); ?></span> 
  1552. </td> 
  1553. </tr> 
  1554. <tr> 
  1555. <td><?php _e('Product thumbnail columns per page', WCPGSK_DOMAIN); ?>:</td> 
  1556. <td> 
  1557. <input name="wcpgsk_settings[filters][woocommerce_product_thumbnails_columns]" type="number" value="<?php if (isset($options['filters']['woocommerce_product_thumbnails_columns'])) echo esc_attr( $options['filters']['woocommerce_product_thumbnails_columns'] ); ?>" size="2" class="regular-text" /> 
  1558. </td> 
  1559. <td> 
  1560. <span class="description"><?php esc_attr(_e('Specify the number of product thumbnail columns you want to show on a shop page.', WCPGSK_DOMAIN)); ?></span> 
  1561. </td> 
  1562. </tr> 
  1563.  
  1564. <tr> 
  1565. <td width="25%"><?php _e( 'Default state of create account', WCPGSK_DOMAIN ); ?></td> 
  1566. <td> 
  1567. <input class="checkbox" name="wcpgsk_settings[filters][woocommerce_create_account_default_checked]" id="wcpgsk_create_account" value="0" type="hidden"> 
  1568. <input class="checkbox" name="wcpgsk_settings[process][woocommerce_create_account_default_checked]" id="wcpgsk_create_account" value="1" type="checkbox" <?php if ( isset( $options['filters']['woocommerce_create_account_default_checked'] ) && 1 == ($options['filters']['woocommerce_create_account_default_checked'])) echo "checked='checked'"; ?> type="checkbox"> 
  1569. </td> 
  1570. <td> 
  1571. <span class="description"><?php _e('Control the default state of the create account checkbox in checkout', WCPGSK_DOMAIN); ?></span> 
  1572. </td> 
  1573.  
  1574. </tr> 
  1575. <tr> 
  1576. <td width="25%"><?php _e( 'Enable Fast Cart', WCPGSK_DOMAIN ); ?></td> 
  1577. <td> 
  1578. <input class="checkbox" name="wcpgsk_settings[process][fastcart]" id="wcpgsk_fastcart" value="0" type="hidden"> 
  1579. <input class="checkbox" name="wcpgsk_settings[process][fastcart]" id="wcpgsk_fastcart" value="1" type="checkbox" <?php if ( 1 == ($options['process']['fastcart'])) echo "checked='checked'"; ?> type="checkbox"> 
  1580. </td> 
  1581. <td> 
  1582. <span class="description"><?php _e('This option takes customers to cart after adding an item. Do not activate both, Fast Cart and Fast Checkout...', WCPGSK_DOMAIN); ?></span> 
  1583. </td> 
  1584.  
  1585. </tr> 
  1586. <tr> 
  1587. <td width="25%"><?php _e( 'Enable Fast Checkout', WCPGSK_DOMAIN ); ?></td> 
  1588. <td> 
  1589. <input class="checkbox" name="wcpgsk_settings[process][fastcheckout]" id="wcpgsk_fastcheckout" value="0" type="hidden"> 
  1590. <input class="checkbox" name="wcpgsk_settings[process][fastcheckout]" id="wcpgsk_fastcheckout" value="1" type="checkbox" <?php if ( 1 == ($options['process']['fastcheckout'])) echo "checked='checked'"; ?> type="checkbox"> 
  1591. </td> 
  1592. <td> 
  1593. <span class="description"><?php _e('This option takes customers to checkout after adding an item. Do not activate both, Fast Cart and Fast Checkout...', WCPGSK_DOMAIN); ?></span> 
  1594. </td> 
  1595. </tr> 
  1596. <tr> 
  1597. <td width="25%"><?php _e( 'Enable Payment Gateways Configuration', WCPGSK_DOMAIN ); ?></td> 
  1598. <td> 
  1599. <input class="checkbox" name="wcpgsk_settings[process][paymentgateways]" id="wcpgsk_paymentgateways" value="0" type="hidden"> 
  1600. <input class="checkbox" name="wcpgsk_settings[process][paymentgateways]" id="wcpgsk_paymentgateways" value="1" type="checkbox" <?php if ( 1 == ($options['process']['paymentgateways'])) echo "checked='checked'"; ?> type="checkbox"> 
  1601. </td> 
  1602. <td> 
  1603. <span class="description"><?php _e('This option allows you to configure the available payment gateways for each product.', WCPGSK_DOMAIN); ?></span> 
  1604. </td> 
  1605. </tr> 
  1606. <?php do_action( 'wcpgsk_settings_shop_after', $options ); ?> 
  1607. </tbody> 
  1608. </table> 
  1609. <?php submit_button( __( 'Save Changes', WCPGSK_DOMAIN ) ); ?> 
  1610.  
  1611. </div> 
  1612. <?php do_action( 'wcpgsk_settings_page_labels', $options ); ?> 
  1613. <?php do_action( 'wcpgsk_settings_page_email', $options ); ?> 
  1614.  
  1615. <?php do_action( 'wcpgsk_settings_page_two', $options ); ?> 
  1616.  
  1617. <h3 class="wcpgsk_acc_header"><?php echo __('Cart Settings', WCPGSK_DOMAIN); ?></h3> 
  1618. <div> 
  1619. <table class="widefat" border="1" > 
  1620. <thead> 
  1621. <tr> 
  1622. <th><?php _e('Settings Name', WCPGSK_DOMAIN); ?></th> 
  1623. <th width="50%"><?php _e('Data', WCPGSK_DOMAIN); ?></th>  
  1624. <th><?php _e('Comments', WCPGSK_DOMAIN); ?></th> 
  1625. </tr> 
  1626. </thead> 
  1627. <tbody> 
  1628. <?php do_action( 'wcpgsk_settings_cart_before', $options ); ?>  
  1629. <tr> 
  1630. <td><?php _e('Add empty cart button to cart', WCPGSK_DOMAIN); ?>:</td> 
  1631. <td> 
  1632. <input name="wcpgsk_settings[cart][addemptycart]" type="hidden" value="0" /> 
  1633. <input name="wcpgsk_settings[cart][addemptycart]" type="checkbox" value="1" <?php if ( 1 == ($options['cart']['addemptycart'])) echo "checked='checked'"; ?> /> 
  1634. </td> 
  1635. <td> 
  1636. <span class="description"><?php _e('Allow your customers to empty the cart.', WCPGSK_DOMAIN); ?></span> 
  1637. </td> 
  1638. </tr> 
  1639. <tr> 
  1640. <td width="25%"><?php _e( 'Empty Cart Label', WCPGSK_DOMAIN ); ?></td> 
  1641. <td> 
  1642. <input name="wcpgsk_settings[process][emptycartlabel]" type="text" id="wcpgsk_emptycartlabel" value="<?php echo isset( $options['process']['emptycartlabel'] ) ? $options['process']['emptycartlabel'] : ''; ?>" class="regular-text" /> 
  1643. </td> 
  1644. <td> 
  1645. <span class="description"><?php _e('Label for the empty cart button.', WCPGSK_DOMAIN); ?></span> 
  1646. </td> 
  1647. </tr> 
  1648. <tr> 
  1649. <td width="25%"><?php _e( 'Confirm Empty Cart Label', WCPGSK_DOMAIN ); ?></td> 
  1650. <td> 
  1651. <input name="wcpgsk_settings[process][confirmemptycart]" type="text" id="wcpgsk_confirmemptycart" value="<?php echo isset( $options['process']['confirmemptycart'] ) ? $options['process']['confirmemptycart'] : ''; ?>" class="regular-text" /> 
  1652. </td> 
  1653. <td> 
  1654. <span class="description"><?php _e('Leave this blank to allow empty cart action without confirmation.', WCPGSK_DOMAIN); ?></span> 
  1655. </td> 
  1656. </tr> 
  1657.  
  1658. <tr> 
  1659. <td><?php _e('Minimum cart items', WCPGSK_DOMAIN); ?>:</td> 
  1660. <td> 
  1661. <input name="wcpgsk_settings[cart][minitemscart]" type="text" value="<?php if (isset($options['cart']['minitemscart'])) echo esc_attr( $options['cart']['minitemscart'] ); ?>" size="2" class="regular-text" /> 
  1662. </td> 
  1663. <td> 
  1664. <span class="description"><?php esc_attr(_e('You can specify the minimum of items allowed in woocommerce customer carts for wholesale purposes. If you leave this blank 0 (=option deactivated) will be established. Please be aware that you have to set the maximum to the same or a higher limit. This value will be automatically adjusted to assure store operations.', WCPGSK_DOMAIN)); ?></span> 
  1665. </td> 
  1666. </tr> 
  1667. <tr> 
  1668. <td><?php _e('Maximum cart items', WCPGSK_DOMAIN); ?>:</td> 
  1669. <td> 
  1670. <input name="wcpgsk_settings[cart][maxitemscart]" type="text" value="<?php if (isset($options['cart']['maxitemscart'])) echo esc_attr( $options['cart']['maxitemscart'] ); ?>" size="2" class="regular-text" /> 
  1671. </td> 
  1672. <td> 
  1673. <span class="description"><?php _e('You can specify the maximum of items allowed in woocommerce customer carts. If you leave this blank 0 (=option deactivated) will be established.', WCPGSK_DOMAIN); ?></span> 
  1674. </td> 
  1675. </tr> 
  1676. <tr> 
  1677. <td><?php _e('Treat variation items like individual (different) product items when counting items in cart', WCPGSK_DOMAIN); ?>:</td> 
  1678. <td> 
  1679. <input name="wcpgsk_settings[cart][variationscountasproduct]" type="hidden" value="0" /> 
  1680. <input name="wcpgsk_settings[cart][variationscountasproduct]" type="checkbox" value="1" <?php if ( 1 == ($options['cart']['variationscountasproduct'])) echo "checked='checked'"; ?> /> 
  1681. </td> 
  1682. <td> 
  1683. <span class="description"><?php _e('If you want to allow users to buy the maximum of variations allowed, even if the the product maximum is reached, do not check this option. Minimum handling takes this into account, too.', WCPGSK_DOMAIN); ?></span> 
  1684. </td> 
  1685. </tr> 
  1686. <tr> 
  1687. <td><?php _e('Maximum global cart quantity', WCPGSK_DOMAIN); ?>:</td> 
  1688. <td> 
  1689. <input name="wcpgsk_settings[cart][maxqtycart]" type="text" value="<?php if (isset($options['cart']['maxqtycart'])) echo esc_attr( $options['cart']['maxqtycart'] ); ?>" size="3" class="regular-text" /> 
  1690. </td> 
  1691. <td> 
  1692. <span class="description"><?php _e('You can specify the allowed overall maximum (sum of all item quantities). If you leave this blank, 0 (=option deactivated) will be established.', WCPGSK_DOMAIN); ?></span> 
  1693. </td> 
  1694. </tr> 
  1695. <tr> 
  1696. <td><?php _e('Minimum global cart quantity', WCPGSK_DOMAIN); ?>:</td> 
  1697. <td> 
  1698. <input name="wcpgsk_settings[cart][minqtycart]" type="text" value="<?php if (isset($options['cart']['minqtycart'])) echo esc_attr( $options['cart']['minqtycart'] ); ?>" size="3" class="regular-text" /> 
  1699. </td> 
  1700. <td> 
  1701. <span class="description"><?php _e('You can specify the required overall minimum (sum of all item quantities). If you leave this blank, 0 (=option deactivated) will be established.', WCPGSK_DOMAIN); ?></span> 
  1702. </td> 
  1703. </tr> 
  1704. <tr> 
  1705. <td><?php _e('Allow min/max/step configuration on per product basis', WCPGSK_DOMAIN); ?>:</td> 
  1706. <td> 
  1707. <input name="wcpgsk_settings[cart][minmaxstepproduct]" type="hidden" value="0" /> 
  1708. <input name="wcpgsk_settings[cart][minmaxstepproduct]" type="checkbox" value="1" <?php if ( 1 == ($options['cart']['minmaxstepproduct'])) echo "checked='checked'"; ?> /> 
  1709. </td> 
  1710. <td> 
  1711. <span class="description"><?php _e('If you want to configure minimum/maximum and steps for item quantities, enable this checkbox. Individual product settings take precedence over the following global settings.', WCPGSK_DOMAIN); ?></span> 
  1712. </td> 
  1713. </tr> 
  1714.  
  1715. <tr> 
  1716. <td><?php _e('Switch off quantity input', WCPGSK_DOMAIN); ?>:</td> 
  1717. <td> 
  1718. <?php 
  1719. $noquantity = __('No quantity input for', WCPGSK_DOMAIN); 
  1720. $quantity = __('Quantity input for', WCPGSK_DOMAIN); 
  1721. ?> 
  1722. <select name="wcpgsk_settings[cart][variationproductnoqty]" class="wcpgsk_qty_select"> 
  1723. <option value="1" <?php if ($options['cart']['variationproductnoqty'] == 1) echo "selected"; ?> ><?php echo $noquantity . ' ' . __('Product Variation', WCPGSK_DOMAIN);?></option>  
  1724. <option value="0" <?php if ($options['cart']['variationproductnoqty'] == 0) echo "selected"; ?> ><?php echo $quantity . ' ' . __('Product Variation', WCPGSK_DOMAIN);?></option> 
  1725. </select><br /> 
  1726. <select name="wcpgsk_settings[cart][variableproductnoqty]" class="wcpgsk_qty_select"> 
  1727. <option value="1" <?php if ($options['cart']['variableproductnoqty'] == 1) echo "selected"; ?> ><?php echo $noquantity . ' ' . __('Variable Product', WCPGSK_DOMAIN);?></option>  
  1728. <option value="0" <?php if ($options['cart']['variableproductnoqty'] == 0) echo "selected"; ?> ><?php echo $quantity . ' ' . __('Variable Product', WCPGSK_DOMAIN);?></option> 
  1729. </select><br /> 
  1730. <!-- Does not apply 
  1731. <select name="wcpgsk_settings[cart][groupedproductnoqty]" class="wcpgsk_qty_select"> 
  1732. <option value="1" <?php //if ($options['cart']['groupedproductnoqty'] == 1) echo "selected"; ?> ><?php //echo $noquantity . ' ' . __('Grouped Product', WCPGSK_DOMAIN);?></option>  
  1733. <option value="0" <?php //if ($options['cart']['groupedproductnoqty'] == 0) echo "selected"; ?> ><?php //echo $quantity . ' ' . __('Grouped Product', WCPGSK_DOMAIN);?></option> 
  1734. </select><br /> 
  1735. --> 
  1736. <select name="wcpgsk_settings[cart][externalproductnoqty]" class="wcpgsk_qty_select"> 
  1737. <option value="1" <?php if ($options['cart']['externalproductnoqty'] == 1) echo "selected"; ?> ><?php echo $noquantity . ' ' . __('External Product', WCPGSK_DOMAIN);?></option> 
  1738. <option value="0" <?php if ($options['cart']['externalproductnoqty'] == 0) echo "selected"; ?> ><?php echo $quantity . ' ' . __('External Product', WCPGSK_DOMAIN);?></option> 
  1739. </select><br /> 
  1740.  
  1741. <select name="wcpgsk_settings[cart][simpleproductnoqty]" class="wcpgsk_qty_select"> 
  1742. <option value="1" <?php if ($options['cart']['simpleproductnoqty'] == 1) echo "selected"; ?> ><?php echo $noquantity . ' ' . __('Simple Product', WCPGSK_DOMAIN);?></option>  
  1743. <option value="0" <?php if ($options['cart']['simpleproductnoqty'] == 0) echo "selected"; ?> ><?php echo $quantity . ' ' . __('Simple Product', WCPGSK_DOMAIN);?></option> 
  1744. </select> 
  1745. </td> 
  1746. <td> 
  1747. <span class="description"><?php _e('Switch off the quantity input field and set quantity automatically to one if a customer adds a product or product variation to his/her cart.', WCPGSK_DOMAIN); ?></span> 
  1748. </td> 
  1749. </tr> 
  1750. <?php 
  1751. $product_types = array('variation' => __('Set the minimum and maximum quantities allowed for each item that a customer can add to his/her cart', WCPGSK_DOMAIN),  
  1752. 'variable' => __('Please, you should not confuse product quantity and the allowed maximum and minimum of individual items in a cart.', WCPGSK_DOMAIN),  
  1753. //does not apply 'grouped' => __('The min and max quantity values only have effect if you enable quantity input for a given product type. To disable this functionality you can set this value to 0.', WCPGSK_DOMAIN),  
  1754. 'external' => __('To squizze out more of WooCommerce you may want to upgrade to WooCommerce Rich Guys Swiss Knife :-).', WCPGSK_DOMAIN),  
  1755. 'simple' => __('Individual items can be personalized by Woocommerce Rich Guys Swiss Knife during checkout.', WCPGSK_DOMAIN)); 
  1756. foreach($product_types as $type => $descr) : 
  1757. $minqty = !empty($options['cart']['minqty_' . $type]) ? $options['cart']['minqty_' . $type] : 0; 
  1758. $maxqty = !empty($options['cart']['maxqty_' . $type]) ? $options['cart']['maxqty_' . $type] : 0; 
  1759. $stepqty = !empty($options['cart']['stepqty_' . $type]) ? $options['cart']['stepqty_' . $type] : 0; 
  1760.  
  1761. ?> 
  1762. <tr> 
  1763. <td><?php _e('Min/Max/Step quantity <strong>' . $type . ' products', WCPGSK_DOMAIN); ?></strong>:</td> 
  1764. <td> 
  1765. <input name="wcpgsk_settings[cart][minqty_<?php echo $type ; ?>]" type="text" value="<?php echo $minqty; ?>" size="2" class="wcpgsk_textfield_short" /> | 
  1766. <input name="wcpgsk_settings[cart][maxqty_<?php echo $type ; ?>]" type="text" value="<?php echo $maxqty ; ?>" size="2" class="wcpgsk_textfield_short" /> | 
  1767. <input name="wcpgsk_settings[cart][stepqty_<?php echo $type ; ?>]" type="text" value="<?php echo $stepqty ; ?>" size="2" class="wcpgsk_textfield_short" /> 
  1768. </td> 
  1769. <td> 
  1770. <span class="description"><?php echo $descr ; ?></span> 
  1771. </td> 
  1772. </tr> 
  1773. <?php 
  1774. endforeach; 
  1775. ?> 
  1776.  
  1777. <?php do_action( 'wcpgsk_settings_cart_after', $options ); ?> 
  1778.  
  1779. </tbody> 
  1780. </table> 
  1781. <?php submit_button( __( 'Save Changes', WCPGSK_DOMAIN ) ); ?> 
  1782. </div> 
  1783. <?php do_action( 'wcpgsk_settings_page_four', $options ); ?> 
  1784. <h3 class="wcpgsk_acc_header"><?php echo __('Checkout Settings', WCPGSK_DOMAIN); ?></h3> 
  1785. <div> 
  1786. <table class="widefat" border="1" > 
  1787. <thead> 
  1788. <tr> 
  1789. <th><?php _e('Settings Name', WCPGSK_DOMAIN); ?></th> 
  1790. <th><?php _e('Data', WCPGSK_DOMAIN); ?></th>  
  1791. <th><?php _e('Comments', WCPGSK_DOMAIN); ?></th> 
  1792. </tr> 
  1793. </thead> 
  1794. <tbody> 
  1795. <?php do_action( 'wcpgsk_settings_checkout_before', $options ); ?> 
  1796. <tr> 
  1797. <td><?php _e('Min date offset for date fields', WCPGSK_DOMAIN); ?>:</td> 
  1798. <td> 
  1799. <input name="wcpgsk_settings[checkoutform][mindate]" type="text" value="<?php if (!empty($options['checkoutform']['mindate'])) echo esc_attr( $options['checkoutform']['mindate'] ); ?>" size="2" class="regular-text" /> 
  1800. </td> 
  1801. <td> 
  1802. <span class="description"><?php _e('For date fields you can specify a minimum offset in number of days.', WCPGSK_DOMAIN); ?></span> 
  1803. </td> 
  1804. </tr> 
  1805. <tr> 
  1806. <td><?php _e('Max date offset for date fields', WCPGSK_DOMAIN); ?>:</td> 
  1807. <td> 
  1808. <input name="wcpgsk_settings[checkoutform][maxdate]" type="text" value="<?php if (!empty($options['checkoutform']['maxdate'])) echo esc_attr( $options['checkoutform']['maxdate'] ); ?>" size="3" class="regular-text" /> 
  1809. </td> 
  1810. <td> 
  1811. <span class="description"><?php _e('For date fields you can specify a maximum offset in number of days.', WCPGSK_DOMAIN); ?></span> 
  1812. </td> 
  1813. </tr> 
  1814. <tr> 
  1815. <td><?php _e('Use calendar style time picker', WCPGSK_DOMAIN); ?>:</td> 
  1816. <td> 
  1817. <input name="wcpgsk_settings[checkoutform][caltimepicker]" type="hidden" value="0" /> 
  1818. <input name="wcpgsk_settings[checkoutform][caltimepicker]" type="checkbox" value="1" <?php if ( isset( $options['checkoutform']['caltimepicker'] ) && 1 == ($options['checkoutform']['caltimepicker'])) echo "checked='checked'"; ?> /> 
  1819. </td> 
  1820. <td> 
  1821. <span class="description"><?php _e('Use alternative presentation for time picker fields.', WCPGSK_DOMAIN); ?></span> 
  1822. </td> 
  1823. </tr> 
  1824. <tr> 
  1825. <td><?php _e('Css class', WCPGSK_DOMAIN); ?>:</td> 
  1826. <td> 
  1827. <input name="wcpgsk_settings[checkoutform][cssclass]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['checkoutform']['cssclass'])) echo esc_attr( $options['checkoutform']['cssclass'] ); ?>" class="regular-text" /> 
  1828. </td> 
  1829. <td> 
  1830. <span class="description"><?php _e('You can add one or more css classes to custom fields. Use space as separator.', WCPGSK_DOMAIN); ?></span> 
  1831. </td> 
  1832. </tr> 
  1833. <tr> 
  1834. <td><?php _e('Additional billing fields title', WCPGSK_DOMAIN); ?>:</td> 
  1835. <td> 
  1836. <input name="wcpgsk_settings[checkoutform][morebillingtitle]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['checkoutform']['morebillingtitle'])) echo esc_attr( $options['checkoutform']['morebillingtitle'] ); ?>" class="regular-text" /> 
  1837. </td> 
  1838. <td> 
  1839. <span class="description"><?php _e('You can set the additional billing information section title used in emails and order receipts. If you leave this field empty the section title will be omitted.', WCPGSK_DOMAIN); ?></span> 
  1840. </td> 
  1841. </tr> 
  1842. <tr> 
  1843. <td><?php _e('Additional shipping fields title', WCPGSK_DOMAIN); ?>:</td> 
  1844. <td> 
  1845. <input name="wcpgsk_settings[checkoutform][moreshippingtitle]" type="text" class="wcpgsk_textfield" value="<?php if (!empty($options['checkoutform']['moreshippingtitle'])) echo esc_attr( $options['checkoutform']['moreshippingtitle'] ); ?>" class="regular-text" /> 
  1846. </td> 
  1847. <td> 
  1848. <span class="description"><?php _e('You can set the additional shipping information section title used in emails and order receipts. If you leave this field empty the section title will be omitted.', WCPGSK_DOMAIN); ?></span> 
  1849. </td> 
  1850. </tr> 
  1851.  
  1852. <tr> 
  1853. <td><?php _e('Add billing email validator', WCPGSK_DOMAIN); ?>:</td> 
  1854. <td> 
  1855. <input name="wcpgsk_settings[checkoutform][billingemailvalidator]" type="hidden" value="0" /> 
  1856. <input name="wcpgsk_settings[checkoutform][billingemailvalidator]" type="checkbox" value="1" <?php if ( 1 == ($options['checkoutform']['billingemailvalidator'])) echo "checked='checked'"; ?> /> 
  1857. </td> 
  1858. <td> 
  1859. <span class="description"><?php _e('If you want to oblige the user to input his/her email a second time and to assure that the email is valid, activate. This field will be added automatically.', WCPGSK_DOMAIN); ?></span> 
  1860. </td> 
  1861. </tr> 
  1862. <tr> 
  1863. <td><?php _e('Checkout Script', WCPGSK_DOMAIN); ?>:</td> 
  1864. <td> 
  1865. <textarea name="wcpgsk_checkoutjs" id="wcpgsk_checkoutjs"><?php echo get_option('wcpgsk_checkoutjs') ;?></textarea> 
  1866. <button onclick="save_checkoutjs();return false;"><?php _e('Save js', WCPGSK_DOMAIN); ?></button> 
  1867. <span id="result_save_checkoutjs"></span> 
  1868. </td> 
  1869. <td> 
  1870. <span class="description"><?php _e('You can save your own js code for the checkout page here. Only code, no tags!', WCPGSK_DOMAIN); ?></span> 
  1871. <br /> 
  1872. <span class="description"><?php _e('Please use with care as this may break things if not handled with care.', WCPGSK_DOMAIN); ?></span> 
  1873. <br /> 
  1874. <span class="description"><?php _e('You can include your script by editing wcpgsk_user.js too but you will have to restore your changes after every update of this plugin.', WCPGSK_DOMAIN); ?></span> 
  1875. </td> 
  1876. </tr> 
  1877. <?php do_action('wcpgsk_settings_checkout_after', $options); ?> 
  1878.  
  1879. </tbody> 
  1880. </table> 
  1881. <?php submit_button( __( 'Save Changes', WCPGSK_DOMAIN ) ); ?> 
  1882. </div> 
  1883. <?php 
  1884. do_action( 'wcpgsk_settings_page_six', $options ); 
  1885.  
  1886. //if ( function_exists('WC') ) : 
  1887. ?> 
  1888. <h3 class="wcpgsk_acc_header"><?php echo __('Woocommerce Checkout Localization', WCPGSK_DOMAIN); ?></h3> 
  1889. <div> 
  1890. <table class="widefat" border="1" > 
  1891. <thead> 
  1892. <tr> 
  1893. <th><?php _e('Field Name', WCPGSK_DOMAIN); ?></th> 
  1894. <th><?php _e('Default Behaviour', WCPGSK_DOMAIN); ?></th>  
  1895. <th><?php _e('Comments', WCPGSK_DOMAIN); ?></th> 
  1896. </tr> 
  1897. </thead> 
  1898. <tbody> 
  1899. <?php 
  1900. $jsfields = $this->wcpgsk_get_country_locale_field_selectors(); 
  1901. foreach ($jsfields as $field => $fieldids) : 
  1902. ?> 
  1903. <tr> 
  1904. <td><?php echo $field; ?></td> 
  1905. <td> 
  1906. <input name="wcpgsk_settings[checkoutform][default_<?php echo $field; ?>]" type="hidden" value="0" /> 
  1907. <input name="wcpgsk_settings[checkoutform][default_<?php echo $field; ?>]" type="checkbox" value="1" <?php if ( isset($options['checkoutform']['default_' . $field]) && 1 == ($options['checkoutform']['default_' . $field])) echo "checked='checked'"; ?> /> 
  1908. </td> 
  1909. <td> 
  1910. <span class="description"><?php echo __('Let WCPGSK handle localization for fields of type', WCPGSK_DOMAIN) . ' ' . $field; ?></span> 
  1911. </td> 
  1912. </tr> 
  1913.  
  1914. <?php 
  1915. endforeach; 
  1916. ?> 
  1917. </tbody> 
  1918. </table> 
  1919. <table class="widefat" border="1" > 
  1920. <thead> 
  1921. <tr> 
  1922. <th><?php _e('Field Name', WCPGSK_DOMAIN); ?></th> 
  1923. <th><?php _e('Data', WCPGSK_DOMAIN); ?></th>  
  1924. <th><?php _e('Comments', WCPGSK_DOMAIN); ?></th> 
  1925. </tr> 
  1926. </thead> 
  1927. <tbody> 
  1928.  
  1929. <tr> 
  1930. <td><?php _e('Field Localization', WCPGSK_DOMAIN); ?></td> 
  1931. <td> 
  1932. <select name="wcpgsk_configcountry" id="wcpgsk_configcountry" onChange="get_locale_fields_form()">  
  1933. <option value=""><?php echo __('Select Locale', WCPGSK_DOMAIN); ?></option> 
  1934. <option value="default"><?php _e('Default Locale', WCPGSK_DOMAIN); ?></option> 
  1935. <?php 
  1936. $countries = $this->wcpgsk_get_allowed_countries();//WC()->countries->countries; 
  1937.  
  1938. foreach ($countries as $cc => $cn) :  
  1939. echo '<option value="' . $cc . '">' . $cn . '</option>'; 
  1940. endforeach; 
  1941. ?> 
  1942. </select> 
  1943. </td> 
  1944. <td> 
  1945. <?php _e('Select country to configure', WCPGSK_DOMAIN); ?> 
  1946. </td> 
  1947.  
  1948. </tr> 
  1949. </tbody> 
  1950. <tbody id="locale_field_form"> 
  1951. </tbody> 
  1952.  
  1953. </table> 
  1954. <?php submit_button( __( 'Save Changes', WCPGSK_DOMAIN ) ); ?> 
  1955.  
  1956. </div> 
  1957. <?php 
  1958.  
  1959. $checkoutforms = array('billing' => 'Billing', 'shipping' => 'Shipping'); 
  1960. $checkoutforms = apply_filters( 'wcpgsk_checkoutforms', $checkoutforms ); 
  1961. foreach($checkoutforms as $section => $title) : 
  1962. ?> 
  1963. <h3 class="wcpgsk_acc_header"><?php echo __('Woocommerce Checkout ' . $title . ' Section', WCPGSK_DOMAIN); ?></h3> 
  1964. <div> 
  1965. <table class="wcpgsk_fieldtable widefat" id="wcpgsk_<?php echo $section ;?>_table" border="1" > 
  1966. <thead> 
  1967. <tr> 
  1968. <th class="wcpgsk_replace"><?php _e('Order', WCPGSK_DOMAIN); ?></th> 
  1969. <th><?php _e('Field Name', WCPGSK_DOMAIN); ?></th> 
  1970. <th><?php _e('Remove Field', WCPGSK_DOMAIN); ?></th>  
  1971. <th><?php _e('Required Field', WCPGSK_DOMAIN); ?></th> 
  1972. <th><?php _e('Hide in Receipts', WCPGSK_DOMAIN); ?></th> 
  1973. <th><span title="<?php esc_attr_e('Store only in customer context, do not include in order', WCPGSK_DOMAIN); ?>"><?php _e('Customer data', WCPGSK_DOMAIN); ?></span></th> 
  1974. <th class="wcpgsk_replace"><?php _e('Label', WCPGSK_DOMAIN); ?></th> 
  1975. <th class="wcpgsk_replace"><?php _e('Placeholder', WCPGSK_DOMAIN); ?></th> 
  1976. <th class="wcpgsk_replace"><?php _e('Display', WCPGSK_DOMAIN); ?></th> 
  1977. <th class="wcpgsk_replace"><?php _e('Type', WCPGSK_DOMAIN); ?></th> 
  1978. </tr> 
  1979. </thead> 
  1980. <tbody> 
  1981. <tr> 
  1982. <td></td> 
  1983. <td></td> 
  1984. <td><input type="checkbox" class="select_removes" for="removes_<?php echo $section ;?>" id="select_remove_<?php echo $section ;?>" value="1" /> <?php _e('Select All', WCPGSK_DOMAIN); ?></td> 
  1985. <td><input type="checkbox" class="select_required" for="required_<?php echo $section ;?>" id="select_required_<?php echo $section ;?>" value="1" /> <?php _e('Select All', WCPGSK_DOMAIN); ?></td> 
  1986. <td></td> 
  1987. <td></td> 
  1988. <td></td> 
  1989. <td></td> 
  1990. <td></td> 
  1991. <td></td> 
  1992. </tr> 
  1993. <?php  
  1994. if ($section == 'order') : 
  1995. $checkout_fields = array(); 
  1996. $checkout_fields = apply_filters( 'wcpgsk_order_checkout_fields', $checkout_fields, $options ); 
  1997. elseif ($section == 'shared') : 
  1998. $checkout_fields = array(); 
  1999. $checkout_fields = apply_filters( 'wcpgsk_shared_checkout_fields', $checkout_fields, $options ); 
  2000. else: 
  2001. $checkout_fields = $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), $section . '_' ); 
  2002. $field_order = 1; 
  2003. foreach ($checkout_fields as $key => $field) : 
  2004.  
  2005. $checkout_fields[$key]['placeholder'] = isset($checkout_fields[$key]['placeholder']) ? $checkout_fields[$key]['placeholder'] : ''; 
  2006. $checkout_fields[$key]['label'] = isset($checkout_fields[$key]['label']) ? $checkout_fields[$key]['label'] : ''; 
  2007. $checkout_fields[$key]['required'] = isset($checkout_fields[$key]['required']) ? $checkout_fields[$key]['required'] : 0; 
  2008.  
  2009. $checkout_fields[$key]['fieldkey'] = $key; 
  2010. $checkout_fields[$key]['displaylabel'] = isset($options['woofields']['label_' . $key]) && !empty($field['label']) ? __($field['label'], WCPGSK_DOMAIN) : $key; 
  2011. $checkout_fields[$key]['order'] = ((isset($options['woofields']['order_' . $key]) && !empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order); 
  2012. //$checkout_fields[$key]['placeholder'] = ((isset($options['woofields']['placeholder_' . $key]) && !empty($options['woofields']['placeholder_' . $key])) ? $options['woofields']['placeholder_' . $key] : $checkout_fields[$key]['placeholder']); 
  2013. $checkout_fields[$key]['placeholder'] = ((isset($options['woofields']['placeholder_' . $key])) ? $options['woofields']['placeholder_' . $key] : $checkout_fields[$key]['placeholder']); 
  2014. $checkout_fields[$key]['label'] = ((isset($options['woofields']['label_' . $key])) ? $options['woofields']['label_' . $key] : $checkout_fields[$key]['label']); 
  2015. //$checkout_fields[$key]['label'] = ((isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key])) ? $options['woofields']['label_' . $key] : $checkout_fields[$key]['label']); 
  2016. //before required defreq 
  2017. $checkout_fields[$key]['defreq'] = ((isset($checkout_fields[$key]['required']) && $checkout_fields[$key]['required'] == 1) ? $defchecked : $defunchecked); 
  2018. $checkout_fields[$key]['required'] = ((isset($options['woofields']['required_' . $key])) ? $options['woofields']['required_' . $key] : $checkout_fields[$key]['required']); 
  2019. $checkout_fields[$key]['customeronly'] = ((isset($options['woofields']['customeronly_' . $key])) ? $options['woofields']['customeronly_' . $key] : 0); 
  2020. $checkout_fields[$key]['hideorder'] = ((isset($options['woofields']['hideorder_' . $key])) ? $options['woofields']['hideorder_' . $key] : 0); 
  2021. $checkout_fields[$key]['type'] = ((isset($options['woofields']['type_' . $key]) && !empty($options['woofields']['type_' . $key])) ? $options['woofields']['type_' . $key] : ((!empty($checkout_fields[$key]['type'])) ? $checkout_fields[$key]['type'] : 'text') ); 
  2022.  
  2023. $checkout_fields[$key]['classsel'] = ((isset($options['woofields']['class_' . $key]) && !empty($options['woofields']['class_' . $key])) ? $options['woofields']['class_' . $key] : ((isset($checkout_fields[$key]['class'])) ? $checkout_fields[$key]['class'][0] : 'form-row-wide') ); 
  2024. $checkout_fields[$key]['settings'] = ((isset($options['woofields']['settings_' . $key]) && !empty($options['woofields']['settings_' . $key])) ? $options['woofields']['settings_' . $key] : '' ); 
  2025. $field_order++; 
  2026. endforeach; 
  2027. endif; 
  2028. $checkout_fields = apply_filters( 'wcpgsk_checkout_fields', $checkout_fields, $options ); 
  2029. uasort( $checkout_fields, array($this, "compareFieldOrder") );  
  2030. $field_order = 1; 
  2031.  
  2032. foreach ($checkout_fields as $key => $field) :  
  2033. $fieldLabel = $field['displaylabel']; 
  2034. $options['woofields'][$section][$key]['custom_' . $key] = isset($options['woofields'][$section][$key]['custom_' . $key]) ? $options['woofields'][$section][$key]['custom_' . $key] : ''; 
  2035. ?> 
  2036. <tr class="wcpgsk_order_row"> 
  2037. <td class="wcpgsk_order_col"><span class="ui-icon ui-icon-arrow-4"></span><span class="wcpgsk_order_span"><?php echo $field['order']; ?></span><input type="hidden" class="wcpgsk_order_input" name="wcpgsk_settings[woofields][order_<?php echo $field['fieldkey']; ?>]" value="<?php echo $field['order']; ?>" /></td> 
  2038. <td> 
  2039. <?php 
  2040. if ($options['woofields'][$section][$key]['custom_' . $key] == $key && $key != 'order_comments') : 
  2041. ?> 
  2042. <input name="wcpgsk_settings[woofields][<?php echo $section ;?>][<?php echo $key; ?>][custom_<?php echo $key; ?>]" type="hidden" value="<?php echo $key; ?>" /> 
  2043. <button class="wcpgsk_remove_field" for="wcpgsk_<?php echo $section ;?>_table" name="wcpgsk_settings[woofields][<?php echo $section ;?>][<?php echo $key; ?>][fieldname_<?php echo $key; ?>]"><?php _e('X', WCPGSK_DOMAIN) ; ?></button> <?php echo $key; ?> 
  2044. <?php 
  2045. else : 
  2046. if ($section == 'order' && $key == 'order_comments') : 
  2047. ?> 
  2048. <input name="wcpgsk_settings[woofields][<?php echo $section ;?>][<?php echo $key; ?>][custom_<?php echo $key; ?>]" type="hidden" value="<?php echo $key; ?>" /> 
  2049. <?php 
  2050. endif; 
  2051. echo $fieldLabel;  
  2052. endif; 
  2053. ?> 
  2054. </td> 
  2055. <td><input name="wcpgsk_settings[woofields][remove_<?php echo $field['fieldkey']; ?>]" type="hidden" value="0" /> 
  2056. <input name="wcpgsk_settings[woofields][remove_<?php echo $field['fieldkey']; ?>]" type="checkbox" class="removes_<?php echo $section ;?>" value="1"  
  2057. <?php if ( isset($options['woofields']['remove_' . $field['fieldkey']]) && 1 == ($options['woofields']['remove_' . $field['fieldkey']]) ) echo 'checked="checked"'; ?> /></td> 
  2058. <td><input name="wcpgsk_settings[woofields][required_<?php echo $field['fieldkey']; ?>]" type="hidden" value="0" /> 
  2059. <input name="wcpgsk_settings[woofields][required_<?php echo $field['fieldkey']; ?>]" type="checkbox" class="required_<?php echo $section ;?>" value="1" <?php if ( 1 == $field['required'] ) echo "checked='checked'"; ?> /> 
  2060. <small> <?php echo $field['defreq']; ?></small> 
  2061. </td> 
  2062. <td><input name="wcpgsk_settings[woofields][hideorder_<?php echo $field['fieldkey']; ?>]" type="hidden" value="0" /> 
  2063. <input name="wcpgsk_settings[woofields][hideorder_<?php echo $field['fieldkey']; ?>]" type="checkbox" class="hideorder_<?php echo $section ;?>" value="1" <?php if ( 1 == $field['hideorder'] ) echo "checked='checked'"; ?> /> 
  2064. </td> 
  2065. <td><input name="wcpgsk_settings[woofields][customeronly_<?php echo $field['fieldkey']; ?>]" type="hidden" value="0" /> 
  2066. <input name="wcpgsk_settings[woofields][customeronly_<?php echo $field['fieldkey']; ?>]" type="checkbox" class="customeronly_<?php echo $section ;?>" value="1" <?php if ( isset( $field['customeronly'] ) && 1 == $field['customeronly'] ) echo "checked='checked'"; ?> /> 
  2067. </td> 
  2068. <td><input type="text" name="wcpgsk_settings[woofields][label_<?php echo $field['fieldkey']; ?>]" class="wcpgsk_textfield"  
  2069. value="<?php echo esc_attr( $field['label'] ); ?>" /></td> 
  2070. <td><input type="text" name="wcpgsk_settings[woofields][placeholder_<?php echo $field['fieldkey']; ?>]" class="wcpgsk_textfield"  
  2071. value="<?php echo esc_attr( $field['placeholder'] ); ?>" /></td> 
  2072. <td> 
  2073. <select name="wcpgsk_settings[woofields][class_<?php echo $field['fieldkey']; ?>]"> 
  2074. <option value="form-row-wide"  
  2075. <?php if ( 'form-row-wide' == ($field['classsel']) ) echo 'selected="selected"'; ?>><?php echo $placeWide; ?></option> 
  2076. <option value="form-row-first"  
  2077. <?php if ( 'form-row-first' == ($field['classsel']) ) echo 'selected="selected"'; ?>><?php echo $placeFirst; ?></option> 
  2078. <option value="form-row-last"  
  2079. <?php if ( 'form-row-last' == ($field['classsel']) ) echo 'selected="selected"'; ?>><?php echo $placeLast; ?></option> 
  2080. </select> 
  2081. </td> 
  2082. <td class="wcpgsk_functions_col"> 
  2083. <?php 
  2084. if ($options['woofields'][$section][$key]['custom_' . $key] == $key && $key != 'order_comments') : 
  2085. ?> 
  2086. <button class="wcpgsk_configure_field" table="wcpgsk_<?php echo $section ;?>_table" for="<?php echo $key ; ?>" type="<?php echo $field['type'] ; ?>" name="wcpgsk_settings[woofields][button_<?php echo $key ; ?>]"><?php echo $field['type'] ; ?></button> 
  2087. <input name="wcpgsk_settings[woofields][type_<?php echo $key; ?>]" type="hidden" value="<?php echo $field['type'] ; ?>" /> 
  2088. <input name="wcpgsk_settings[woofields][settings_<?php echo $key; ?>]" type="hidden" value="<?php echo $field['settings'] ; ?>" /> 
  2089. <?php 
  2090. else : 
  2091. echo $field['type'];  
  2092. endif; 
  2093. ?> 
  2094. </td> 
  2095. </tr> 
  2096. <?php  
  2097. $field_order++; 
  2098. endforeach;  
  2099. $custom = 'nn2id'; 
  2100. $newField = __('New Field', WCPGSK_DOMAIN); 
  2101. ?> 
  2102.  
  2103. <tr valign="top" class="wcpgsk_add_field_row" id="wcpgsk_add_<?php echo $section ;?>_field_row"> 
  2104. <td class="wcpgsk_order_col"><span class="ui-icon ui-icon-arrow-4"></span><span class="wcpgsk_order_span"><?php echo $custom; ?></span><input type="hidden" class="wcpgsk_order_input" convert="wcpgsk_settings[woofields][order_<?php echo $custom ; ?>]" value="<?php echo $custom; ?>" /></td> 
  2105. <td class="wcpgsk_fieldname_col"> 
  2106. <input convert="wcpgsk_settings[woofields][<?php echo $section ;?>][<?php echo $custom; ?>][custom_<?php echo $custom; ?>]" type="hidden" value="<?php echo $custom; ?>" /> 
  2107.  
  2108. <button class="wcpgsk_remove_field" for="wcpgsk_<?php echo $section ;?>_table" convert="wcpgsk_settings[woofields][fieldname_<?php echo $custom; ?>]"><?php _e('X', WCPGSK_DOMAIN) ; ?></button> <span convert="wcpgsk_settings[woofields][ident_<?php echo $custom; ?>]"><?php echo $custom; ?></span> 
  2109. </td> 
  2110. <td><input convert="wcpgsk_settings[woofields][remove_<?php echo $custom; ?>]" type="hidden" value="0" /> 
  2111. <input convert="wcpgsk_settings[woofields][remove_<?php echo $custom; ?>]" type="checkbox" class="removes_<?php echo $section ;?>" value="1" /></td> 
  2112. <td><input convert="wcpgsk_settings[woofields][required_<?php echo $custom; ?>]" type="hidden" value="0" /> 
  2113. <input convert="wcpgsk_settings[woofields][required_<?php echo $custom; ?>]" type="checkbox" class="required_<?php echo $section ;?>" value="1" /> 
  2114. </td> 
  2115. <td><input convert="wcpgsk_settings[woofields][hideorder_<?php echo $custom; ?>]" type="hidden" value="0" /> 
  2116. <input convert="wcpgsk_settings[woofields][hideorder_<?php echo $custom; ?>]" type="checkbox" class="hideorder_<?php echo $section ;?>" value="1" /> 
  2117. </td> 
  2118. <td><input convert="wcpgsk_settings[woofields][customeronly_<?php echo $custom; ?>]" type="hidden" value="0" /> 
  2119. <input convert="wcpgsk_settings[woofields][customeronly_<?php echo $custom; ?>]" type="checkbox" class="customeronly_<?php echo $section ;?>" value="1" /> 
  2120. </td> 
  2121. <td><input type="text" convert="wcpgsk_settings[woofields][label_<?php echo $custom; ?>]" class="wcpgsk_textfield" value="<?php echo $newField; ?>" /></td> 
  2122. <td><input type="text" convert="wcpgsk_settings[woofields][placeholder_<?php echo $custom; ?>]" class="wcpgsk_textfield" value="<?php echo $newField; ?>" /></td> 
  2123. <td> 
  2124. <select convert="wcpgsk_settings[woofields][class_<?php echo $custom; ?>]"> 
  2125. <option value="form-row-wide"><?php echo $placeWide ?></option> 
  2126. <option value="form-row-first"><?php echo $placeFirst ?></option> 
  2127. <option value="form-row-last" ><?php echo $placeLast ?></option> 
  2128. </select> 
  2129. </td> 
  2130. <td class="wcpgsk_functions_col"> 
  2131. <button convert="wcpgsk_settings[woofields][button_<?php echo $custom; ?>]"></button> 
  2132. <input convert="wcpgsk_settings[woofields][type_<?php echo $custom; ?>]" type="hidden" value="" /> 
  2133. <input convert="wcpgsk_settings[woofields][settings_<?php echo $custom; ?>]" type="hidden" value="" /> 
  2134. </td> 
  2135. </tr> 
  2136. </tbody> 
  2137. </table> 
  2138. Select type: <select id="wcpgsk_<?php echo $section ;?>_table_type"> 
  2139. <option value="text">text</option> 
  2140. <option value="textarea">textarea</option> 
  2141. <option value="date">date</option> 
  2142. <option value="time" >time</option> 
  2143. <option value="number" >number</option> 
  2144. <option value="select" >select</option> 
  2145. <?php 
  2146. do_action( 'wcpgsk_settings_form_field_types', $options );  
  2147. ?> 
  2148. </select> 
  2149.  
  2150. Identifier New Field: <input type="text" id="wcpgsk_<?php echo $section ;?>_table_fieldid" value="" maxlength="25" size="12" /> <a href="javascript:;" class="add_custom_field button-primary" id="add_custom_<?php echo $section ;?>_btn" for="wcpgsk_<?php echo $section ;?>_table" placeholder="<?php echo $section ;?>"><?php _e( 'New ' . $title . ' Field' , WCPGSK_DOMAIN ); ?></a> 
  2151. <?php submit_button( __( 'Save Changes', WCPGSK_DOMAIN ) ); ?> 
  2152. </div> 
  2153.  
  2154. <?php 
  2155. endforeach; 
  2156. do_action( 'wcpgsk_settings_page_eight', $options ); 
  2157. do_action( 'wcpgsk_settings_page_about', $options ); 
  2158. ?> 
  2159.  
  2160. </div> 
  2161. <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="<?php _e('Save Changes'); ?>" /></p> 
  2162. </form> 
  2163.  
  2164. <div id="wcpgsk_error_dialog" title="WC Poor Guys Swiss Knife Error"> 
  2165. <p id="wcpgsk_error_message"></p> 
  2166. </div> 
  2167.  
  2168. <?php 
  2169. do_action( 'wcpgsk_settings_page_dialogs_one', $options ); 
  2170. $validateTip = __('Required form fields are marked with *.', WCPGSK_DOMAIN); 
  2171.  
  2172. ?> 
  2173. <div id="wcpgsk_dialog_form_container" title="<?php _e('Configure your custom field', WCPGSK_DOMAIN) ; ?>"> 
  2174.  
  2175. </div> 
  2176.  
  2177. <div id="wcpgsk_dialog_form_select" title="Configure Select Field" class="wcpgsk_dialog_forms"> 
  2178. <p class="validateTips"><?php echo $validateTip ; ?></p> 
  2179. <form for="wcpgsk_dlg_form_select" accept-charset="utf-8"> 
  2180. <table class="wcpgsfieldkconfig"> 
  2181. <tr class="field_option field_option_choices"> 
  2182. <td class="label"> 
  2183. <label><?php _e('Options', WCPGSK_DOMAIN) ; ?>*</label> 
  2184. <p><?php _e('Enter each option on a new line.', WCPGSK_DOMAIN) ; ?> 
  2185. <br /><?php _e('You can specify value and label for each option like this:', WCPGSK_DOMAIN) ; ?> 
  2186. </p> 
  2187. <p><strong>jazz : Charles Mingus<br>blues : John Lee Hooker</strong></p> 
  2188. </td> 
  2189. <td> 
  2190. <textarea rows="6" for="wcpgsk_add_options" class="textarea field_option-choices" autocomplete="off" defaultValue="" placeholder=""></textarea>  
  2191. </td> 
  2192. </tr> 
  2193. <tr class="field_option field_option_select"> 
  2194. <td class="label"> 
  2195. <label><?php _e('Default Value', WCPGSK_DOMAIN) ; ?></label> 
  2196. <p><?php _e('Specify default values, one per line.', WCPGSK_DOMAIN) ; ?></p> 
  2197. </td> 
  2198. <td> 
  2199. <textarea rows="3" for="wcpgsk_add_selected" class="textarea" defaultValue="" placeholder=""></textarea>  
  2200. </td> 
  2201. </tr> 
  2202. <tr class="field_option field_option_select"> 
  2203. <td class="label"> 
  2204. <label><?php _e('Allow Null?', WCPGSK_DOMAIN) ; ?></label> 
  2205. </td> 
  2206. <td> 
  2207. <ul class="wcpgsk-radio-list radio horizontal"><li><label><input id="wcpgsk_add_allow_null_1" for="wcpgsk_add_allow_null" value="1" type="radio"><?php _e('Yes', WCPGSK_DOMAIN) ; ?></label></li><li><label><input id="wcpgsk_add_allow_null_0" for="wcpgsk_add_allow_null" value="0" checked=""checked"" data-checked=""checked"" type="radio"><?php _e('No', WCPGSK_DOMAIN) ; ?></label></li></ul>  
  2208. </td> 
  2209. </tr> 
  2210. <tr class="field_option field_option_select"> 
  2211. <td class="label"> 
  2212. <label><?php _e('Select multiple values?', WCPGSK_DOMAIN) ; ?></label> 
  2213. </td> 
  2214. <td> 
  2215. <ul class="wcpgsk-radio-list radio horizontal"><li><label><input id="wcpgsk_add_multiple_1" for="wcpgsk_add_multiple" value="1" type="radio"><?php _e('Yes', WCPGSK_DOMAIN) ; ?></label></li><li><label><input id="wcpgsk_add_multiple_0" for="wcpgsk_add_multiple" value="0" checked=""checked"" data-checked=""checked"" type="radio"><?php _e('No', WCPGSK_DOMAIN) ; ?></label></li></ul>  
  2216. </td> 
  2217. </tr> 
  2218. <tr class="field_option"> 
  2219. <td class="label"> 
  2220. <label><?php _e('Presentation', WCPGSK_DOMAIN) ; ?></label> 
  2221.  
  2222. </td> 
  2223. <td> 
  2224. <select for="wcpgsk_add_presentation"> 
  2225. <option value="select"><?php _e('As select list', WCPGSK_DOMAIN) ; ?></option> 
  2226. <option value="radio"><?php _e('As radio buttons', WCPGSK_DOMAIN) ; ?></option> 
  2227. <option value="checkbox"><?php _e('As checkboxes', WCPGSK_DOMAIN) ; ?></option> 
  2228. </select> 
  2229. </td> 
  2230. </tr> 
  2231.  
  2232.  
  2233. </table> 
  2234. </form> 
  2235.  
  2236. </div> 
  2237.  
  2238. <div id="wcpgsk_dialog_form_text" title="Configure Text Field" class="wcpgsk_dialog_forms"> 
  2239. <form for="wcpgsk_dlg_form_text"> 
  2240. <table class="wcpgsfieldkconfig"> 
  2241. <tr class="field_option"> 
  2242. <td class="label"> 
  2243. <label><?php _e('Maximum characters', WCPGSK_DOMAIN) ; ?></label> 
  2244. <p><?php _e('Maxlength attribute for input tag. Value has to be a number.', WCPGSK_DOMAIN) ; ?></p> 
  2245.  
  2246. </td> 
  2247. <td> 
  2248. <input type="text" for="wcpgsk_add_maxlength" value="" /> 
  2249. </td> 
  2250. </tr> 
  2251. <tr class="field_option"> 
  2252. <td class="label"> 
  2253. <label><?php _e('Size', WCPGSK_DOMAIN) ; ?></label> 
  2254. <p><?php _e('Size attribute for input tag. Value has to be a number.', WCPGSK_DOMAIN) ; ?></p> 
  2255. </td> 
  2256. <td> 
  2257. <input type="text" for="wcpgsk_add_size" value="" /> 
  2258. </td> 
  2259. </tr> 
  2260. <tr class="field_option"> 
  2261. <td class="label"> 
  2262. <label><?php _e('Pattern attribute', WCPGSK_DOMAIN) ; ?></label> 
  2263. <p><?php _e('Value has to be a regular expression. A regular expression can be used to establish or substitute validation. Example: .{3, 5} will require at least 3 characters and allow for a maximum of five. Examples for html5 pattern attributes can be found <a href="http://html5pattern.com/" target="_blank">here</a>. In some circumstances, the symbols ^ in front and $ at the end provide some magical improvements for your regular expressions. Please test on all browsers!', WCPGSK_DOMAIN) ; ?></p>  
  2264. </td> 
  2265. <td> 
  2266. <input type="text" for="wcpgsk_add_pattern" value="" /> 
  2267. </td> 
  2268. </tr> 
  2269. <tr class="field_option"> 
  2270. <td class="label"> 
  2271. <label><?php _e('Validation', WCPGSK_DOMAIN) ; ?></label> 
  2272.  
  2273. </td> 
  2274. <td> 
  2275. <select for="wcpgsk_add_validate"> 
  2276. <option value="none"><?php _e('No validation', WCPGSK_DOMAIN) ; ?></option> 
  2277. <option value="email"><?php _e('Email validation', WCPGSK_DOMAIN) ; ?></option>  
  2278. <option value="date"><?php _e('Date', WCPGSK_DOMAIN) ; ?></option> 
  2279. <option value="time"><?php _e('Time', WCPGSK_DOMAIN) ; ?></option> 
  2280. <option value="password"><?php _e('Password', WCPGSK_DOMAIN) ; ?></option> 
  2281. <option value="number"><?php _e('Number', WCPGSK_DOMAIN) ; ?></option> 
  2282. <option value="integer"><?php _e('Integer', WCPGSK_DOMAIN) ; ?></option> 
  2283. <option value="float"><?php _e('Float', WCPGSK_DOMAIN) ; ?></option> 
  2284. <option value="custom1"><?php _e('Custom1', WCPGSK_DOMAIN) ; ?></option> 
  2285. <option value="custom2"><?php _e('Custom2', WCPGSK_DOMAIN) ; ?></option> 
  2286. <option value="custom3"><?php _e('Custom3', WCPGSK_DOMAIN) ; ?></option> 
  2287. </select> 
  2288. </td> 
  2289. </tr> 
  2290. <tr class="field_option field_option_select"> 
  2291. <td class="label"> 
  2292. <label><?php _e('Add repeat input for validation, e.g. email or password fields?', WCPGSK_DOMAIN) ; ?></label> 
  2293. </td> 
  2294. <td> 
  2295. <ul class="wcpgsk-radio-list radio horizontal"><li><label><input id="wcpgsk_add_repeat_field_0" for="wcpgsk_add_repeat_field" value="0" type="radio" checked=""checked"" data-checked=""checked"" ><?php _e('No', WCPGSK_DOMAIN) ; ?></label></li><li><label><input id="wcpgsk_add_repeat_field_1" for="wcpgsk_add_repeat_field" value="1" type="radio"><?php _e('Yes', WCPGSK_DOMAIN) ; ?></label></li></ul>  
  2296. </td> 
  2297. </tr> 
  2298. <tr class="field_option"> 
  2299. <td class="label"> 
  2300. <label><?php _e('Minimum characters', WCPGSK_DOMAIN) ; ?></label> 
  2301. <p><?php _e('Minlength attribute of the input tag. Value has to be a number. (In the Html5 specification but not supported by most browsers)', WCPGSK_DOMAIN) ; ?></p> 
  2302.  
  2303. </td> 
  2304. <td> 
  2305. <input type="text" for="wcpgsk_add_minlength" value="" /> 
  2306. </td> 
  2307. </tr> 
  2308.  
  2309. </table> 
  2310. </form> 
  2311.  
  2312. </div> 
  2313.  
  2314. <div id="wcpgsk_dialog_form_textarea" title="Configure Textarea Field" class="wcpgsk_dialog_forms"> 
  2315. <p class="validateTips"><?php echo $validateTip ; ?></p> 
  2316. <form for="wcpgsk_dlg_form_textarea"> 
  2317. <table class="wcpgsfieldkconfig"> 
  2318. <tr class="field_option"> 
  2319. <td class="label"> 
  2320. <label><?php _e('Textarea rows', WCPGSK_DOMAIN) ; ?></label> 
  2321. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2322.  
  2323. </td> 
  2324. <td> 
  2325. <input type="text" for="wcpgsk_add_rows" value="" /> 
  2326. </td> 
  2327. </tr> 
  2328. <tr class="field_option"> 
  2329. <td class="label"> 
  2330. <label><?php _e('Textarea cols', WCPGSK_DOMAIN) ; ?></label> 
  2331. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2332. </td> 
  2333. <td> 
  2334. <input type="text" for="wcpgsk_add_cols" value="" /> 
  2335. </td> 
  2336. </tr> 
  2337. </table> 
  2338. </form> 
  2339.  
  2340. </div> 
  2341.  
  2342. <div id="wcpgsk_dialog_form_date" title="Configure Date Field" class="wcpgsk_dialog_forms"> 
  2343. <p class="validateTips"><?php echo $validateTip ; ?></p> 
  2344. <form for="wcpgsk_dlg_form_date"> 
  2345. <table class="wcpgsfieldkconfig"> 
  2346. <tr class="field_option"> 
  2347. <td class="label"> 
  2348. <label><?php _e('Minimum offset in days', WCPGSK_DOMAIN) ; ?></label> 
  2349. <p><?php _e('Value has to be a number for dynamic calculation or a fix date in the format specified in Date format', WCPGSK_DOMAIN) ; ?></p>  
  2350. </td> 
  2351. <td> 
  2352. <input type="text" for="wcpgsk_add_mindays" value="" /> 
  2353. </td> 
  2354. </tr> 
  2355. <tr class="field_option"> 
  2356. <td class="label"> 
  2357. <label><?php _e('Maximum offset in days', WCPGSK_DOMAIN) ; ?></label> 
  2358. <p><?php _e('Value has to be a number for dynamic calculation or a fix date in the format specified in Date format', WCPGSK_DOMAIN) ; ?></p> 
  2359. </td> 
  2360. <td> 
  2361. <input type="text" for="wcpgsk_add_maxdays" value="" /> 
  2362. </td> 
  2363. </tr> 
  2364. <tr class="field_option"> 
  2365. <td class="label"> 
  2366. <label><?php _e('Date format', WCPGSK_DOMAIN) ; ?></label> 
  2367. <p><?php _e('Please select a date format.', WCPGSK_DOMAIN) ; ?></p> 
  2368. </td> 
  2369. <td> 
  2370. <select for="wcpgsk_add_dateformat"> 
  2371. <option value="yy/mm/dd">yyyy/mm/dd</option> 
  2372. <option value="mm/dd/yy">mm/dd/yyyy</option> 
  2373. <option value="dd/mm/yy">dd/mm/yyyy</option> 
  2374. </select> 
  2375. </td> 
  2376. </tr> 
  2377. <tr class="field_option"> 
  2378. <td class="label"> 
  2379. <label><?php _e('Exclude weekends', WCPGSK_DOMAIN) ; ?></label> 
  2380. <p><?php _e('If you want to exclude weekends, please check.', WCPGSK_DOMAIN) ; ?></p> 
  2381. </td> 
  2382. <td> 
  2383. <ul class="wcpgsk-radio-list radio horizontal"> 
  2384. <li><label><input id="wcpgsk_add_exweekend_0" for="wcpgsk_add_exweekend" value="0" type="radio" checked="checked" data-checked="checked" ><?php _e('No', WCPGSK_DOMAIN) ; ?></label></li> 
  2385. <li><label><input id="wcpgsk_add_exweekend_1" for="wcpgsk_add_exweekend" value="1" type="radio"><?php _e('Yes', WCPGSK_DOMAIN) ; ?></label></li> 
  2386. </ul>  
  2387. </td> 
  2388. </tr> 
  2389. <tr class="field_option"> 
  2390. <td class="label"> 
  2391. <label><?php _e('Exclude week days', WCPGSK_DOMAIN) ; ?></label> 
  2392. <p><?php _e('Please specify weekdays to exclude using integers separated by coma.', WCPGSK_DOMAIN) ; ?></p> 
  2393. </td> 
  2394. <td> 
  2395. <input type="text" for="wcpgsk_add_daysexcluded" style="width:100%" /> 
  2396. </td> 
  2397. </tr> 
  2398. <tr class="field_option"> 
  2399. <td class="label"> 
  2400. <label><?php _e('Exclude dates', WCPGSK_DOMAIN) ; ?></label> 
  2401. <p><?php _e('Please specify dates like holidays you want to exclude from selection separated by coma.', WCPGSK_DOMAIN) ; ?></p> 
  2402. </td> 
  2403. <td> 
  2404. <input type="text" for="wcpgsk_add_datesexcluded" style="width:100%" /> 
  2405. </td> 
  2406. </tr> 
  2407. </table> 
  2408. </form> 
  2409. </div> 
  2410.  
  2411. <div id="wcpgsk_dialog_form_time" title="Configure Time Field" class="wcpgsk_dialog_forms"> 
  2412. <p class="validateTips"><?php echo $validateTip ; ?></p> 
  2413. <form for="wcpgsk_dlg_form_time"> 
  2414. <table class="wcpgsfieldkconfig"> 
  2415. <tr class="field_option"> 
  2416. <td class="label"> 
  2417. <label><?php _e('Minimum hour', WCPGSK_DOMAIN) ; ?></label> 
  2418. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2419.  
  2420. </td> 
  2421. <td> 
  2422. <input type="text" for="wcpgsk_add_minhour" value="" /> 
  2423. </td> 
  2424. </tr> 
  2425.  
  2426. <tr class="field_option"> 
  2427. <td class="label"> 
  2428. <label><?php _e('Maximum hour', WCPGSK_DOMAIN) ; ?></label> 
  2429. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2430.  
  2431. </td> 
  2432. <td> 
  2433. <input type="text" for="wcpgsk_add_maxhour" value="" /> 
  2434. </td> 
  2435. </tr> 
  2436.  
  2437. <tr class="field_option"> 
  2438. <td class="label"> 
  2439. <label><?php _e('Hour steps', WCPGSK_DOMAIN) ; ?></label> 
  2440. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2441.  
  2442. </td> 
  2443. <td> 
  2444. <input type="text" for="wcpgsk_add_hoursteps" value="" /> 
  2445. </td> 
  2446. </tr> 
  2447. <tr class="field_option"> 
  2448. <td class="label"> 
  2449. <label><?php _e('Minute steps', WCPGSK_DOMAIN) ; ?></label> 
  2450. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2451. </td> 
  2452. <td> 
  2453. <input type="text" for="wcpgsk_add_minutesteps" value="" /> 
  2454. </td> 
  2455. </tr> 
  2456. </table> 
  2457. </form> 
  2458.  
  2459. </div> 
  2460.  
  2461. <div id="wcpgsk_dialog_form_number" title="Configure Number Field" class="wcpgsk_dialog_forms"> 
  2462. <p class="validateTips"><?php echo $validateTip ; ?></p> 
  2463. <form for="wcpgsk_dlg_form_number"> 
  2464. <table class="wcpgsfieldkconfig"> 
  2465. <tr class="field_option"> 
  2466. <td class="label"> 
  2467. <label><?php _e('Default value', WCPGSK_DOMAIN) ; ?></label> 
  2468. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2469. </td> 
  2470. <td> 
  2471. <input type="text" for="wcpgsk_add_value" value="" /> 
  2472. </td> 
  2473. </tr> 
  2474.  
  2475. <tr class="field_option"> 
  2476. <td class="label"> 
  2477. <label><?php _e('Default upper range value', WCPGSK_DOMAIN) ; ?></label> 
  2478. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2479. </td> 
  2480. <td> 
  2481. <input type="text" for="wcpgsk_add_rangemax" value="" /> 
  2482. </td> 
  2483. </tr> 
  2484.  
  2485.  
  2486. <tr class="field_option"> 
  2487. <td class="label"> 
  2488. <label><?php _e('Minimum value', WCPGSK_DOMAIN) ; ?></label> 
  2489. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2490.  
  2491. </td> 
  2492. <td> 
  2493. <input type="text" for="wcpgsk_add_minvalue" value="" /> 
  2494. </td> 
  2495. </tr> 
  2496.  
  2497. <tr class="field_option"> 
  2498. <td class="label"> 
  2499. <label><?php _e('Maximum value', WCPGSK_DOMAIN) ; ?></label> 
  2500. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2501.  
  2502. </td> 
  2503. <td> 
  2504. <input type="text" for="wcpgsk_add_maxvalue" /> 
  2505. </td> 
  2506. </tr> 
  2507.  
  2508. <tr class="field_option"> 
  2509. <td class="label"> 
  2510. <label><?php _e('Number step', WCPGSK_DOMAIN) ; ?></label> 
  2511. <p><?php _e('Value has to be a number', WCPGSK_DOMAIN) ; ?></p> 
  2512.  
  2513. </td> 
  2514. <td> 
  2515. <input type="text" for="wcpgsk_add_numstep" value="" /> 
  2516. </td> 
  2517. </tr> 
  2518. <tr class="field_option"> 
  2519. <td class="label"> 
  2520. <label><?php _e('Presentation', WCPGSK_DOMAIN) ; ?></label> 
  2521.  
  2522. </td> 
  2523. <td> 
  2524. <select for="wcpgsk_add_numpres"> 
  2525. <option value="false"><?php _e('Default', WCPGSK_DOMAIN) ; ?></option> 
  2526. <option value="true"><?php _e('Range with minimum and maximum', WCPGSK_DOMAIN) ; ?></option> 
  2527. <option value="min"><?php _e('Range with minimum', WCPGSK_DOMAIN) ; ?></option> 
  2528. <option value="max"><?php _e('Range with maximum', WCPGSK_DOMAIN) ; ?></option> 
  2529. </select> 
  2530. </td> 
  2531. </tr> 
  2532. </table> 
  2533. </form> 
  2534.  
  2535. </div> 
  2536.  
  2537.  
  2538. <?php 
  2539. do_action( 'wcpgsk_settings_form_field_dialogs', $options );  
  2540.  
  2541. echo '</div>'; 
  2542. echo '<!--unit test options page end-->'; 
  2543.  
  2544.  
  2545. /** 
  2546. * Helper function to order array. 
  2547. * @access public 
  2548. * @param array $a 
  2549. * @param array $b 
  2550. * @since 1.1.0 
  2551. * @return $input (validated) 
  2552. */  
  2553. public function compareFieldOrder($a, $b) { 
  2554. if ($a['order'] == $b['order']) { 
  2555. return 0; 
  2556. return ($a['order'] < $b['order']) ? -1 : 1; 
  2557. }  
  2558.  
  2559. /** 
  2560. * Our Validation for submitted Settings Page. 
  2561. * @access public 
  2562. * @since 1.1.0 
  2563. * @return $input (validated) 
  2564. */  
  2565. public function wcpgsk_options_validate( $input ) { 
  2566. global $woocommerce; 
  2567. //$wcpgsk_options = get_option( 'wcpgsk_settings' ); 
  2568.  
  2569. if ( empty($input['cart']['minitemscart']) ) $input['cart']['minitemscart'] = 0; 
  2570. if ( !ctype_digit($input['cart']['minitemscart']) ) $input['cart']['minitemscart'] = 0; 
  2571. if ( empty($input['cart']['maxitemscart'] ) ) $input['cart']['maxitemscart'] = 0; 
  2572. if ( !ctype_digit($input['cart']['maxitemscart']) ) $input['cart']['maxitemscart'] = 0; 
  2573. $mincart = $input['cart']['minitemscart']; 
  2574. $maxcart = $input['cart']['maxitemscart']; 
  2575. if ($mincart > $maxcart && $maxcart > 0) $input['cart']['minitemscart'] = 1; 
  2576.  
  2577. if ( empty($input['cart']['minqtycart']) ) $input['cart']['minqtycart'] = 0; 
  2578. if ( !ctype_digit($input['cart']['minqtycart']) ) $input['cart']['minqtycart'] = 0; 
  2579. if ( empty($input['cart']['maxqtycart'] ) ) $input['cart']['maxqtycart'] = 0; 
  2580. if ( !ctype_digit($input['cart']['maxqtycart']) ) $input['cart']['maxqtycart'] = 0; 
  2581. $minqtycart = $input['cart']['minqtycart']; 
  2582. $maxqtycart = $input['cart']['maxqtycart']; 
  2583. if ($minqtycart > $maxqtycart && $maxqtycart > 0) $input['cart']['minqtycart'] = 1; 
  2584.  
  2585.  
  2586.  
  2587. //@todo:could be a string, but not vital 
  2588. if (empty($input['checkoutform']['mindate']) || !ctype_digit($input['checkoutform']['mindate'])) $input['checkoutform']['mindate'] = 0; 
  2589. if (empty($input['checkoutform']['maxdate']) || !ctype_digit($input['checkoutform']['maxdate'])) $input['checkoutform']['maxdate'] = 365; 
  2590.  
  2591. $checkout_fields = $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), 'billing_' ); 
  2592. $field_order = 1;  
  2593. foreach ($checkout_fields as $key => $field) :  
  2594. if (empty($input['woofields']['order_' . $key]) || !ctype_digit($input['woofields']['order_' . $key])) $input['woofields']['order_' . $key] = $field_order; 
  2595. $field_order++; 
  2596. endforeach; 
  2597.  
  2598. $checkout_fields = $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), 'shipping_' ); 
  2599. $field_order = 1;  
  2600. foreach ($checkout_fields as $key => $field) :  
  2601. if (empty($input['woofields']['order_' . $key]) || !ctype_digit($input['woofields']['order_' . $key])) $input['woofields']['order_' . $key] = $field_order; 
  2602. $field_order++; 
  2603. endforeach; 
  2604.  
  2605. if ( isset( $input['process']['fastcart'] ) && $input['process']['fastcart'] == 1 && $input['process']['fastcheckout'] == 1) $input['process']['fastcheckout'] = 0; 
  2606.  
  2607. //$product_types = array('variation', 'variable', 'grouped', 'external', 'simple'); 
  2608. $product_types = array('variation', 'variable', 'external', 'simple'); 
  2609. foreach($product_types as $type) : 
  2610. if ( empty($input['cart']['maxqty_' . $type]) ) $input['cart']['maxqty_' . $type] = 0; 
  2611. if ( !ctype_digit($input['cart']['maxqty_' . $type]) ) $input['cart']['maxqty_' . $type] = 0; 
  2612.  
  2613. if ( empty($input['cart']['stepqty_' . $type]) ) $input['cart']['stepqty_' . $type] = 0; 
  2614. if ( !ctype_digit($input['cart']['stepqty_' . $type]) ) $input['cart']['stepqty_' . $type] = 0; 
  2615.  
  2616. if ( empty($input['cart']['minqty_' . $type]) ) $input['cart']['minqty_' . $type] = 0; 
  2617. if ( !ctype_digit($input['cart']['minqty_' . $type]) ) $input['cart']['minqty_' . $type] = 0; 
  2618. //very basic consistency check for quantity settings 
  2619. if ( $input['cart']['minqty_' . $type] > $input['cart']['maxqty_' . $type] && $input['cart']['maxqty_' . $type] > 0 ) $input['cart']['minqty_' . $type] = 1; 
  2620. if ($input['cart']['maxqty_' . $type] == 1) $input['cart'][$type . 'productnoqty'] = 1; 
  2621. endforeach; 
  2622. $input = apply_filters('wcpgsk_validate_settings', $input); 
  2623. return $input; 
  2624.  
  2625. /** 
  2626. * Our filter for customer editing billing and shipping address. 
  2627. * @access public 
  2628. * @param array $address 
  2629. * @since 1.5.1 
  2630. * @return array $address (processed) 
  2631. * @TODO elaborate on this and billing and shipping custom fields, WooCommerce needs the country field present but nothing else... We have ways to improve this. 
  2632. */  
  2633. public function wcpgsk_address_to_edit($address) { 
  2634. global $woocommerce; 
  2635. $options = get_option( 'wcpgsk_settings' ); 
  2636. $field_order = 1;  
  2637. $locale = get_option( 'wcpgsk_locale', array() ); 
  2638. $wc_locale = $this->wcpgsk_get_country_locale(); 
  2639.  
  2640. foreach ($address as $key => $field) : 
  2641. $address[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order);  
  2642.  
  2643. if ( isset($options['woofields']['remove_' . $key]) && $options['woofields']['remove_' . $key] == 1) : 
  2644. $address[$key]['custom_attributes'] = array('style' => 'display:none'); 
  2645. $address[$key]['label'] = ''; 
  2646. $address[$key]['required'] = false; 
  2647.  
  2648. //elseif ( $key == 'billing_email_validator' ) : 
  2649. //$address[$key]['custom_attributes'] = array('style' => 'display:none'); 
  2650. //$address[$key]['label'] = ''; 
  2651. //$address[$key]['required'] = false; 
  2652. else : 
  2653.  
  2654. $is_billing = strpos($key, 'billing_'); 
  2655. $cc = false; 
  2656. $wc_field_handle = false; 
  2657. if ( $is_billing !== false ) : 
  2658. $wc_field_handle = str_replace('billing_', '', $key); 
  2659. if ( isset($address['billing_country']['value']) ) : 
  2660. $cc = $address['billing_country']['value']; 
  2661. else : 
  2662. $cc = $this->wcpgsk_load_address_value($key); 
  2663. endif; 
  2664. else :  
  2665. $wc_field_handle = str_replace('shipping_', '', $key);  
  2666. if ( isset($address['shipping_country']['value']) ) : 
  2667. $cc = $address['shipping_country']['value']; 
  2668. else : 
  2669. $cc = $this->wcpgsk_load_address_value($key); 
  2670. endif; 
  2671.  
  2672. endif; 
  2673. if ( $cc && $wc_field_handle && isset($options['checkoutform']['default_' . $wc_field_handle]) && $options['checkoutform']['default_' . $wc_field_handle] ) : 
  2674. $address[$key] = $this->wcpgsk_config_locale_field($address[$key], $wc_field_handle, $cc, $wc_locale, $locale); 
  2675. else : 
  2676. if ( isset($options['woofields']['label_' . $key]) ) :  
  2677. $address[$key]['label'] = __( $options['woofields']['label_' . $key], WCPGSK_DOMAIN ); 
  2678. endif; 
  2679. if ( isset($options['woofields']['placeholder_' . $key]) ) :  
  2680. $address[$key]['placeholder'] = __( $options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN ); 
  2681. endif; 
  2682. if ( isset($options['woofields']['required_' . $key]) ) : 
  2683. $address[$key]['required'] = ((isset($options['woofields']['required_' . $key])) ? $options['woofields']['required_' . $key] : ( isset($address[$key]['required']) ? $address[$key]['required'] : false ) ); 
  2684. endif; 
  2685. //if (!empty($options['woofields']['class_' . $key])) { 
  2686. if (!empty($address[$key]['class']) && is_array($address[$key]['class'])) : 
  2687. $address[$key]['class'][0] = 'form-row-wide'; 
  2688. else : 
  2689. $address[$key]['class'] = array ('form-row-wide'); 
  2690. endif; 
  2691. endif; 
  2692. endif; 
  2693. $field_order++;  
  2694. endforeach; 
  2695.  
  2696. uasort($address, array($this, "compareFieldOrder"));  
  2697. return $address; 
  2698.  
  2699. public function wcpgsk_load_address_value($key) { 
  2700. global $woocommerce, $current_user; 
  2701. get_currentuserinfo(); 
  2702.  
  2703. $value = get_user_meta( get_current_user_id(), $key, true ); 
  2704.  
  2705. if ( ! $value ) { 
  2706. switch( $key ) { 
  2707. case 'billing_email' : 
  2708. case 'shipping_email' : 
  2709. $value = $current_user->user_email; 
  2710. break; 
  2711. case 'billing_country' : 
  2712. case 'shipping_country' : 
  2713. $value = $woocommerce->countries->get_base_country(); 
  2714. break; 
  2715. case 'billing_state' : 
  2716. case 'shipping_state' : 
  2717. $value = $woocommerce->countries->get_base_state(); 
  2718. break; 
  2719. return $value;  
  2720.  
  2721. public function wcpgsk_config_locale_field($address_field, $wc_field_handle, $countrycode, $wc_locale, $locale) { 
  2722.  
  2723. $default_required = isset($locale['default']['required_' . $wc_field_handle]) ? $locale['default']['required_' . $wc_field_handle] : '0'; 
  2724. $wc_localerequired = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$wc_field_handle]) && isset($wc_locale[$countrycode][$wc_field_handle]['required']) ? ( $wc_locale[$countrycode][$wc_field_handle]['required'] ? '1' : '0' ) : ( isset($wc_locale['default'][$wc_field_handle]['required']) && $wc_locale['default'][$wc_field_handle]['required'] ? '1' : $default_required ); 
  2725. $locale[$countrycode]['required_' . $wc_field_handle] = isset($locale[$countrycode]['required_' . $wc_field_handle]) ? $locale[$countrycode]['required_' . $wc_field_handle] : $wc_localerequired; 
  2726. $address_field['required'] = $locale[$countrycode]['required_' . $wc_field_handle] ? true : false; 
  2727.  
  2728. $default_label = isset($locale['default']['label_' . $wc_field_handle]) ? $locale['default']['label_' . $wc_field_handle] : ''; 
  2729. $wc_localelabel = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$wc_field_handle]) && isset($wc_locale[$countrycode][$wc_field_handle]['label']) ? $wc_locale[$countrycode][$wc_field_handle]['label'] : ( isset($wc_locale['default'][$wc_field_handle]['label']) ? $wc_locale['default'][$wc_field_handle]['label'] : $default_label );  
  2730. $locale[$countrycode]['label_' . $wc_field_handle] = isset($locale[$countrycode]['label_' . $wc_field_handle]) ? $locale[$countrycode]['label_' . $wc_field_handle] : $wc_localelabel; 
  2731. $address_field['label'] = __($locale[$countrycode]['label_' . $wc_field_handle], WCPGSK_DOMAIN); 
  2732.  
  2733. $default_placeholder = isset($locale['default']['placeholder_' . $wc_field_handle]) ? $locale['default']['placeholder_' . $wc_field_handle] : ''; 
  2734. $wc_localeplaceholder = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$wc_field_handle]) && isset($wc_locale[$countrycode][$wc_field_handle]['placeholder']) ? $wc_locale[$countrycode][$wc_field_handle]['placeholder'] : ( isset($wc_locale['default'][$wc_field_handle]['placeholder']) ? $wc_locale['default'][$wc_field_handle]['placeholder'] : $default_placeholder ); 
  2735. $locale[$countrycode]['placeholder_' . $wc_field_handle] = isset($locale[$countrycode]['placeholder_' . $wc_field_handle]) ? $locale[$countrycode]['placeholder_' . $wc_field_handle] : $wc_localeplaceholder; 
  2736. $address_field['placeholder'] = __($locale[$countrycode]['placeholder_' . $wc_field_handle], WCPGSK_DOMAIN); 
  2737.  
  2738. $default_hidden = isset($locale['default']['hidden_' . $wc_field_handle]) ? $locale['default']['hidden_' . $wc_field_handle] : '0'; 
  2739. $wc_localehidden = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$wc_field_handle]) && isset($wc_locale[$countrycode][$wc_field_handle]['hidden']) ? ( $wc_locale[$countrycode][$wc_field_handle]['hidden'] ? '1' : '0' ) : ( isset($wc_locale['default'][$wc_field_handle]['hidden']) && $wc_locale['default'][$wc_field_handle]['hidden'] ? '1' : $default_hidden ); 
  2740. $locale[$countrycode]['hidden_' . $wc_field_handle] = isset($locale[$countrycode]['hidden_' . $wc_field_handle]) ? $locale[$countrycode]['hidden_' . $wc_field_handle] : $wc_localehidden; 
  2741. $address_field['hidden'] = $locale[$countrycode]['hidden_' . $wc_field_handle] == '1' ? true : false;  
  2742. return $address_field; 
  2743.  
  2744. /** 
  2745. * Filter fields for admin user page. 
  2746. * @access public 
  2747. * @param array $show_fields 
  2748. * @since 1.5.3 
  2749. * @changed 1.6.2 
  2750. * @return array $show_fields (processed) 
  2751. */  
  2752. public function wcpgsk_customer_meta_fields($show_fields) { 
  2753. global $woocommerce; 
  2754. $options = get_option( 'wcpgsk_settings' ); 
  2755. $field_order = 1;  
  2756. $address = $show_fields['billing']['fields']; 
  2757. foreach ($address as $key => $field) : 
  2758. $address[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order);  
  2759. if ( isset($options['woofields']['remove_' . $key]) && $options['woofields']['remove_' . $key] == 1) : 
  2760. unset($address[$key]); 
  2761. else : 
  2762. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  2763. $address[$key]['label'] = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  2764. elseif ( empty($options['woofields']['label_' . $key]) ) : 
  2765. $address[$key]['label'] = ''; 
  2766. endif; 
  2767. if ( isset($options['woofields']['placeholder_' . $key]) && !empty($options['woofields']['placeholder_' . $key]) ) : 
  2768. $address[$key]['description'] = __($options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN); 
  2769. endif; 
  2770. endif; 
  2771.  
  2772. $field_order++;  
  2773. endforeach; 
  2774.  
  2775. uasort($address, array($this, "compareFieldOrder"));  
  2776. $show_fields['billing']['fields'] = $address; 
  2777.  
  2778. $field_order = 1;  
  2779. $address = $show_fields['shipping']['fields']; 
  2780. foreach ($address as $key => $field) : 
  2781. $address[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order);  
  2782. if ( isset($options['woofields']['remove_' . $key]) && $options['woofields']['remove_' . $key] == 1) : 
  2783. unset($address[$key]); 
  2784. else : 
  2785. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  2786. $address[$key]['label'] = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  2787. elseif ( empty($options['woofields']['label_' . $key]) ) :  
  2788. $address[$key]['label'] = ''; 
  2789. endif; 
  2790. if ( isset($options['woofields']['placeholder_' . $key]) && !empty($options['woofields']['placeholder_' . $key]) ) : 
  2791. $address[$key]['description'] = __($options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN); 
  2792. endif;  
  2793. endif; 
  2794. $field_order++;  
  2795. endforeach; 
  2796.  
  2797. uasort($address, array($this, "compareFieldOrder"));  
  2798.  
  2799. $show_fields['shipping']['fields'] = $address; 
  2800. return $show_fields; 
  2801.  
  2802. /** 
  2803. * Handle zip/postcode if postcode field has been removed. 
  2804. * @access public 
  2805. * @param string $postval 
  2806. * @since 1.5.3 
  2807. * @return string $postval (processed) 
  2808. */  
  2809. public function wcpgsk_process_myaccount_field_billing_postcode($postval) { 
  2810. $options = get_option( 'wcpgsk_settings' ); 
  2811. if ( isset($options['woofields']['remove_billing_postcode']) && $options['woofields']['remove_billing_postcode'] == 1 && isset($_POST['billing_country']) && !empty($_POST['billing_country']) ) : 
  2812. $country = $_POST['billing_country']; 
  2813. switch ( $country ) : 
  2814. case "GB" : 
  2815. $postval = 'bfpo0000'; 
  2816. break; 
  2817. case "US" : 
  2818. $postval = '00000-0000'; 
  2819. break; 
  2820. case "CH" : 
  2821. $postval = '0000'; 
  2822. break; 
  2823. default: 
  2824. $postval = '0000'; 
  2825. break; 
  2826. endswitch; 
  2827. endif; 
  2828. return $postval; 
  2829.  
  2830. /** 
  2831. * Handle zip/postcode if postcode field has been removed. 
  2832. * @access public 
  2833. * @param string $postval 
  2834. * @since 1.5.3 
  2835. * @return string $postval (processed) 
  2836. */  
  2837. public function wcpgsk_process_myaccount_field_shipping_postcode($postval) { 
  2838. $options = get_option( 'wcpgsk_settings' ); 
  2839. if ( isset($options['woofields']['remove_shipping_postcode']) && $options['woofields']['remove_shipping_postcode'] == 1 && isset($_POST['shipping_country']) && !empty($_POST['shipping_country']) ) : 
  2840. $country = $_POST['shipping_country']; 
  2841. switch ( $country ) : 
  2842. case "GB" : 
  2843. $postval = 'bfpo0000'; 
  2844. break; 
  2845. case "US" : 
  2846. $postval = '00000-0000'; 
  2847. break; 
  2848. case "CH" : 
  2849. $postval = '0000'; 
  2850. break; 
  2851. default: 
  2852. $postval = '0000'; 
  2853. break; 
  2854. endswitch; 
  2855. endif; 
  2856. return $postval; 
  2857.  
  2858. /** 
  2859. * Assure that templates provide our WCPGSK Funtionality correctly. 
  2860. * @access public 
  2861. * @param string $template_name 
  2862. * @param string $template_path 
  2863. * @param string $located 
  2864. * @param mixed $args 
  2865. * @since 1.5.2 
  2866. * @return array $fields (processed) 
  2867. */  
  2868. function wcpgsk_after_template_part( $template_name, $template_path, $located, $args ) { 
  2869. if ( $template_name == 'myaccount/form-edit-address.php' ) : 
  2870. wcpgsk_after_checkout_form($template_name); 
  2871. endif; 
  2872.  
  2873. /** 
  2874. * Update our order shipping address. 
  2875. * @access public 
  2876. * @since 1.5.3 
  2877. * @output Settings page 
  2878. */  
  2879. public function wcpgsk_order_formatted_shipping_address($address) { 
  2880. global $woocommerce; 
  2881. $options = get_option( 'wcpgsk_settings' ); 
  2882. $field_order = 1; 
  2883. $new_address = array(); 
  2884. if ( !isset($address['first_name']) ) $address['first_name'] = ''; 
  2885. if ( !isset($address['last_name']) ) $address['last_name'] = ''; 
  2886. if ( !isset($address['company']) ) $address['company'] = ''; 
  2887. if ( !isset($address['address_1']) ) $address['address_1'] = ''; 
  2888. if ( !isset($address['address_2']) ) $address['address_2'] = ''; 
  2889. if ( !isset($address['city']) ) $address['city'] = ''; 
  2890. if ( !isset($address['state']) ) $address['state'] = ''; 
  2891. if ( !isset($address['postcode']) ) $address['postcode'] = ''; 
  2892. if ( !isset($address['country']) ) $address['country'] = ''; 
  2893.  
  2894. foreach ($address as $key => $field) : 
  2895. $keycheck = 'shipping_' . $key; 
  2896.  
  2897. if ( isset($options['woofields']['remove_' . $keycheck]) && $options['woofields']['remove_' . $keycheck] == 1) : 
  2898. $new_address[$key]['order'] = ((!empty($options['woofields']['order_' . $keycheck]) && ctype_digit($options['woofields']['order_' . $keycheck])) ? $options['woofields']['order_' . $keycheck] : $field_order);  
  2899. $new_address[$key]['value'] = ''; 
  2900. else : 
  2901. $new_address[$key]['order'] = ((!empty($options['woofields']['order_' . $keycheck]) && ctype_digit($options['woofields']['order_' . $keycheck])) ? $options['woofields']['order_' . $keycheck] : $field_order);  
  2902. $new_address[$key]['value'] = $address[$key]; 
  2903. endif; 
  2904. $field_order++;  
  2905. endforeach;  
  2906. uasort($new_address, array($this, "compareFieldOrder")); 
  2907. $address = array(); 
  2908. foreach ($new_address as $key => $field) : 
  2909. $address[$key] = $new_address[$key]['value']; 
  2910. endforeach; 
  2911. return $address; 
  2912.  
  2913. /** 
  2914. * Update our order billing address. 
  2915. * @access public 
  2916. * @since 1.5.3 
  2917. * @output Settings page 
  2918. */  
  2919. public function wcpgsk_order_formatted_billing_address($address) { 
  2920. global $woocommerce; 
  2921. $options = get_option( 'wcpgsk_settings' ); 
  2922. $field_order = 1; 
  2923. $new_address = array(); 
  2924. if ( !isset($address['first_name']) ) $address['first_name'] = ''; 
  2925. if ( !isset($address['last_name']) ) $address['last_name'] = ''; 
  2926. if ( !isset($address['company']) ) $address['company'] = ''; 
  2927. if ( !isset($address['address_1']) ) $address['address_1'] = ''; 
  2928. if ( !isset($address['address_2']) ) $address['address_2'] = ''; 
  2929. if ( !isset($address['city']) ) $address['city'] = ''; 
  2930. if ( !isset($address['state']) ) $address['state'] = ''; 
  2931. if ( !isset($address['postcode']) ) $address['postcode'] = ''; 
  2932. if ( !isset($address['country']) ) $address['country'] = ''; 
  2933.  
  2934. foreach ($address as $key => $field) : 
  2935. $keycheck = 'billing_' . $key; 
  2936.  
  2937. if ( isset($options['woofields']['remove_' . $keycheck]) && $options['woofields']['remove_' . $keycheck] == 1) : 
  2938. $new_address[$key]['order'] = ((!empty($options['woofields']['order_' . $keycheck]) && ctype_digit($options['woofields']['order_' . $keycheck])) ? $options['woofields']['order_' . $keycheck] : $field_order);  
  2939. $new_address[$key]['value'] = ''; 
  2940. else : 
  2941. $new_address[$key]['order'] = ((!empty($options['woofields']['order_' . $keycheck]) && ctype_digit($options['woofields']['order_' . $keycheck])) ? $options['woofields']['order_' . $keycheck] : $field_order);  
  2942. $new_address[$key]['value'] = $address[$key]; 
  2943. endif; 
  2944. $field_order++;  
  2945. endforeach;  
  2946. uasort($new_address, array($this, "compareFieldOrder")); 
  2947. $address = array(); 
  2948. foreach ($new_address as $key => $field) : 
  2949. $address[$key] = $new_address[$key]['value']; 
  2950. endforeach; 
  2951. return $address; 
  2952.  
  2953. /** 
  2954. * Our filter to add billing fields. 
  2955. * @access public 
  2956. * @param array $fields 
  2957. * @since 1.1.0 
  2958. * @return array $fields (processed) 
  2959. */  
  2960. function add_billing_custom_fields( $fields ) { 
  2961. $options = get_option( 'wcpgsk_settings' ); 
  2962. $options['woofields']['label_billing_email_validator'] = !empty($options['woofields']['label_billing_email_validator']) ? $options['woofields']['label_billing_email_validator'] : ''; 
  2963. $options['woofields']['placehoder_billing_email_validator'] = !empty($options['woofields']['placehoder_billing_email_validator']) ? $options['woofields']['placehoder_billing_email_validator'] : ''; 
  2964. $options['woofields']['required_billing_email_validator'] = isset($options['woofields']['required_billing_email_validator']) ? $options['woofields']['required_billing_email_validator'] : 1; 
  2965. if ( !is_user_logged_in() ) :  
  2966. if (isset($options['checkoutform']['billingemailvalidator']) && $options['checkoutform']['billingemailvalidator'] == 1) { 
  2967. $fields['billing_email_validator'] = array( 
  2968. 'type' => 'text',  
  2969. 'label' => __( $options['woofields']['label_billing_email_validator'], WCPGSK_DOMAIN ),  
  2970. 'placeholder' => __( $options['woofields']['placehoder_billing_email_validator'], WCPGSK_DOMAIN ),  
  2971. 'required' => (($options['woofields']['required_billing_email_validator'] == 1) ? true : false),  
  2972. //not necessary... 'validate' => 'email' 
  2973. ); 
  2974. endif; 
  2975. if (isset($options['woofields']['billing']) && is_array($options['woofields']['billing'])) { 
  2976. foreach($options['woofields']['billing'] as $customkey => $customconfig) { 
  2977. //$fieldrepeater = null; 
  2978. $fields[$customkey] = $this->createCustomStandardField($customkey, 'billing', $options['woofields']['type_' . $customkey]); 
  2979. $field_order = 1; 
  2980. foreach ($fields as $key => $field) : 
  2981. $fields[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order);  
  2982.  
  2983. if ( isset($options['woofields']['remove_' . $key]) && $options['woofields']['remove_' . $key] == 1) : 
  2984. $fields[$key]['required'] = false; 
  2985. endif; 
  2986. if ( isset($options['woofields']['required_' . $key]) && $options['woofields']['required_' . $key] != 1) : 
  2987. $fields[$key]['required'] = false; 
  2988. endif; 
  2989. $field_order++; 
  2990. endforeach; 
  2991. uasort($fields, array($this, "compareFieldOrder"));  
  2992. return $fields; 
  2993.  
  2994. /** 
  2995. * Our filter to add shipping fields. 
  2996. * @access public 
  2997. * @param array $fields 
  2998. * @since 1.1.0 
  2999. * @return array $fields (processed) 
  3000. */  
  3001. function add_shipping_custom_fields( $fields ) { 
  3002. $options = get_option( 'wcpgsk_settings' ); 
  3003.  
  3004. if (isset($options['woofields']['shipping']) && is_array($options['woofields']['shipping'])) { 
  3005. foreach($options['woofields']['shipping'] as $customkey => $customconfig) { 
  3006. $fields[$customkey] = $this->createCustomStandardField($customkey, 'shipping', $options['woofields']['type_' . $customkey]); 
  3007. $field_order = 1; 
  3008. foreach ($fields as $key => $field) : 
  3009. $fields[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order);  
  3010. if ( isset($options['woofields']['remove_' . $key]) && $options['woofields']['remove_' . $key] == 1) : 
  3011. $fields[$key]['required'] = false; 
  3012. endif; 
  3013. $field_order++; 
  3014. endforeach; 
  3015. uasort($fields, array($this, "compareFieldOrder"));  
  3016.  
  3017.  
  3018. return $fields; 
  3019.  
  3020. /** 
  3021. * Our filter for billing fields. 
  3022. * @access public 
  3023. * @param array $fields 
  3024. * @since 1.1.0 
  3025. * @return array $fields (processed) 
  3026. */  
  3027. public function wcpgsk_admin_billing_fields($fields) { 
  3028. global $woocommerce; 
  3029. $options = get_option( 'wcpgsk_settings' ); 
  3030. $billing_fields = array(); 
  3031. $field_order = 1;  
  3032. $checkout_fields = $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), 'billing_' ); 
  3033. $defchecked = __('Default: checked', WCPGSK_DOMAIN); 
  3034. $defunchecked = __('Default: unchecked', WCPGSK_DOMAIN); 
  3035.  
  3036. foreach ($checkout_fields as $key => $field) : 
  3037. $checkout_fields[$key]['required'] = isset( $checkout_fields[$key]['required'] ) ? $checkout_fields[$key]['required'] : 0; 
  3038. $checkout_fields[$key]['label'] = !empty($checkout_fields[$key]['label']) ? $checkout_fields[$key]['label'] : ''; 
  3039. $checkout_fields[$key]['placeholder'] = !empty($checkout_fields[$key]['placeholder']) ? $checkout_fields[$key]['placeholder'] : ''; 
  3040. $checkout_fields[$key]['fieldkey'] = $key; 
  3041. $checkout_fields[$key]['displaylabel'] = !empty($field['label']) ? __($field['label'], WCPGSK_DOMAIN) : $key; 
  3042. $checkout_fields[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order); 
  3043. $checkout_fields[$key]['placeholder'] = ((!empty($options['woofields']['placeholder_' . $key])) ? $options['woofields']['placeholder_' . $key] : $checkout_fields[$key]['placeholder']); 
  3044. $checkout_fields[$key]['label'] = ((!empty($options['woofields']['label_' . $key])) ? $options['woofields']['label_' . $key] : $checkout_fields[$key]['label']); 
  3045. //$checkout_fields[$key]['label'] = ((isset($options['woofields']['label_' . $key])) ? $options['woofields']['label_' . $key] : $checkout_fields[$key]['label']); 
  3046. //before required defreq 
  3047. $checkout_fields[$key]['defreq'] = ((isset($checkout_fields[$key]['required']) && $checkout_fields[$key]['required'] == 1) ? $defchecked : $defunchecked); 
  3048. $checkout_fields[$key]['required'] = ((isset($options['woofields']['required_' . $key])) ? $options['woofields']['required_' . $key] : $checkout_fields[$key]['required']); 
  3049. $checkout_fields[$key]['hideorder'] = ((isset($options['woofields']['hideorder_' . $key])) ? $options['woofields']['hideorder_' . $key] : 0); 
  3050. $checkout_fields[$key]['type'] = ((!empty($options['woofields']['type_' . $key])) ? $options['woofields']['type_' . $key] : ((!empty($checkout_fields[$key]['type'])) ? $checkout_fields[$key]['type'] : 'text') ); 
  3051. $checkout_fields[$key]['classsel'] = ((!empty($options['woofields']['class_' . $key])) ? $options['woofields']['class_' . $key] : ((isset($checkout_fields[$key]['class'])) ? $checkout_fields[$key]['class'][0] : 'form-row-wide') ); 
  3052. $checkout_fields[$key]['settings'] = ((!empty($options['woofields']['settings_' . $key])) ? $options['woofields']['settings_' . $key] : '' ); 
  3053. $field_order++; 
  3054. endforeach; 
  3055.  
  3056. uasort($checkout_fields, array($this, "compareFieldOrder"));  
  3057.  
  3058. foreach ($checkout_fields as $key => $field) :  
  3059. //$fieldLabel = $field['displaylabel']; 
  3060. $fieldkey = str_replace('billing_', '', $key); 
  3061. if (isset($fields[$fieldkey])):  
  3062. //@TODO: this will never return nothing as $fields does not hold any keys according to $fieldkey 
  3063. $billing_fields[$fieldkey] = $fields[$fieldkey]; 
  3064. else: 
  3065. //if ($key != 'billing_email_validator' && $field['hideorder'] == 0) : 
  3066. if ($key != 'billing_email_validator') : 
  3067. if ( isset( $options['woofields']['billing'][$key]['custom_' . $key] ) && $options['woofields']['billing'][$key]['custom_' . $key] ) : 
  3068. $configField = $this->createCustomStandardField($key, 'billing', $options['woofields']['type_' . $key]); 
  3069. if (isset($configField['class'])) unset($configField['class']); 
  3070. if (isset($configField['clear'])) unset($configField['clear']); 
  3071. if (isset($configField['placeholder'])) unset($configField['placeholder']); 
  3072. if (isset($configField['required'])) unset($configField['required']); 
  3073. if (isset($configField['validate'])) unset($configField['validate']); 
  3074. if (isset($configField['custom_attributes'])) unset($configField['custom_attributes']); 
  3075.  
  3076. if (!isset($configField['label'])) $configField['label'] = __($checkout_fields[$key]['label'], WCPGSK_DOMAIN); 
  3077.  
  3078. //show select values as text in this case 
  3079. if ( !empty($configField['type']) && $configField['type'] == 'select' ) $configField['type'] = 'text'; 
  3080. //textarea is not recognized by woocommerce in order billing address context 
  3081. if ( !empty($configField['type']) && $configField['type'] == 'textarea' ) $configField['type'] = 'text'; 
  3082. //if ( !empty($configField['type']) && $configField['type'] == 'fileupload' ) $configField['type'] = 'text'; 
  3083. //if ($field['hideorder'] == 0) 
  3084. $configField['show'] = true; 
  3085. //else 
  3086. // $configField['show'] = false; 
  3087.  
  3088. $billing_fields[$fieldkey] = $configField; 
  3089. endif; 
  3090. endif; 
  3091. endif; 
  3092.  
  3093. endforeach; 
  3094. return apply_filters( 'wcpgsk_admin_billing_fields', $billing_fields );  
  3095.  
  3096. /** 
  3097. * Our filter for shipping fields. 
  3098. * @access public 
  3099. * @param array $fields 
  3100. * @since 1.1.0 
  3101. * @return array $fields (processed) 
  3102. */  
  3103. public function wcpgsk_admin_shipping_fields($fields) { 
  3104. global $woocommerce; 
  3105. $defchecked = __('Default: checked', WCPGSK_DOMAIN); 
  3106. $defunchecked = __('Default: unchecked', WCPGSK_DOMAIN); 
  3107. $options = get_option( 'wcpgsk_settings' ); 
  3108. $shipping_fields = array(); 
  3109. $field_order = 1;  
  3110. $checkout_fields = $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), 'shipping_' ); 
  3111. $field_order = 1; 
  3112.  
  3113. foreach ($checkout_fields as $key => $field) : 
  3114. $checkout_fields[$key]['required'] = isset( $checkout_fields[$key]['required'] ) ? $checkout_fields[$key]['required'] : 0; 
  3115. $checkout_fields[$key]['label'] = !empty($checkout_fields[$key]['label']) ? $checkout_fields[$key]['label'] : ''; 
  3116. $checkout_fields[$key]['placeholder'] = !empty($checkout_fields[$key]['placeholder']) ? $checkout_fields[$key]['placeholder'] : ''; 
  3117.  
  3118. $checkout_fields[$key]['fieldkey'] = $key; 
  3119. $checkout_fields[$key]['displaylabel'] = !empty($field['label']) ? __($field['label'], WCPGSK_DOMAIN) : $key; 
  3120. $checkout_fields[$key]['order'] = ((!empty($options['woofields']['order_' . $key]) && ctype_digit($options['woofields']['order_' . $key])) ? $options['woofields']['order_' . $key] : $field_order); 
  3121. $checkout_fields[$key]['placeholder'] = ((!empty($options['woofields']['placeholder_' . $key])) ? $options['woofields']['placeholder_' . $key] : $checkout_fields[$key]['placeholder']); 
  3122. $checkout_fields[$key]['label'] = ((!empty($options['woofields']['label_' . $key])) ? $options['woofields']['label_' . $key] : $checkout_fields[$key]['label']); 
  3123. //before required defreq 
  3124. $checkout_fields[$key]['defreq'] = ((isset($checkout_fields[$key]['required']) && $checkout_fields[$key]['required'] == 1) ? $defchecked : $defunchecked); 
  3125. $checkout_fields[$key]['required'] = ((isset($options['woofields']['required_' . $key])) ? $options['woofields']['required_' . $key] : $checkout_fields[$key]['required']); 
  3126. $checkout_fields[$key]['hideorder'] = ((isset($options['woofields']['hideorder_' . $key])) ? $options['woofields']['hideorder_' . $key] : 0); 
  3127. $checkout_fields[$key]['type'] = ((!empty($options['woofields']['type_' . $key])) ? $options['woofields']['type_' . $key] : ((!empty($checkout_fields[$key]['type'])) ? $checkout_fields[$key]['type'] : 'text') ); 
  3128.  
  3129. $checkout_fields[$key]['classsel'] = ((!empty($options['woofields']['class_' . $key])) ? $options['woofields']['class_' . $key] : ((isset($checkout_fields[$key]['class'])) ? $checkout_fields[$key]['class'][0] : 'form-row-wide') ); 
  3130. $checkout_fields[$key]['settings'] = ((!empty($options['woofields']['settings_' . $key])) ? $options['woofields']['settings_' . $key] : '' ); 
  3131. $field_order++; 
  3132. endforeach; 
  3133.  
  3134. uasort($checkout_fields, array($this, "compareFieldOrder"));  
  3135.  
  3136. foreach ($checkout_fields as $key => $field) :  
  3137. //$fieldLabel = $field['displaylabel']; 
  3138. $fieldkey = str_replace('shipping_', '', $key); 
  3139. if (isset($fields[$fieldkey])):  
  3140. $shipping_fields[$fieldkey] = $fields[$fieldkey]; 
  3141. else: 
  3142. if ($key != 'shipping_email_validator') : 
  3143. if ( isset( $options['woofields']['shipping'][$key]['custom_' . $key] ) && $options['woofields']['shipping'][$key]['custom_' . $key] ) : 
  3144. $configField = $this->createCustomStandardField($key, 'shipping', $options['woofields']['type_' . $key]); 
  3145. //unset(configField['placeholder']); 
  3146. if (isset($configField['class'])) unset($configField['class']); 
  3147. if (isset($configField['clear'])) unset($configField['clear']); 
  3148. if (isset($configField['placeholder'])) unset($configField['placeholder']); 
  3149. if (isset($configField['required'])) unset($configField['required']); 
  3150. if (isset($configField['validate'])) unset($configField['validate']); 
  3151. if (isset($configField['custom_attributes'])) unset($configField['custom_attributes']); 
  3152.  
  3153. if (!isset($configField['label'])) $configField['label'] = __($checkout_fields[$key]['label'], WCPGSK_DOMAIN); 
  3154. //show select values as text in this case 
  3155. //show select values as text in this case 
  3156. if ( !empty($configField['type']) && $configField['type'] == 'select' ) $configField['type'] = 'text'; 
  3157. //textarea is not recognized by woocommerce in order billing address context 
  3158. if ( !empty($configField['type']) && $configField['type'] == 'textarea' ) $configField['type'] = 'text'; 
  3159. //if ($field['hideorder'] == 0) 
  3160. $configField['show'] = true; 
  3161. //else 
  3162. // $configField['show'] = false; 
  3163.  
  3164.  
  3165. $shipping_fields[$fieldkey] = $configField; 
  3166. endif; 
  3167. endif; 
  3168. endif; 
  3169.  
  3170. endforeach; 
  3171. return apply_filters( 'wcpgsk_admin_shipping_fields', $shipping_fields );  
  3172.  
  3173. /** 
  3174. * Handle WooCommerce js overwrites of field labels, placeholders, hidden and required status. 
  3175. * @access public 
  3176. * @param array $params 
  3177. * @since 1.7.1 
  3178. * @return array $params 
  3179. */  
  3180. public function wcpgsk_address_i18n_params($params) { 
  3181. $options = get_option( 'wcpgsk_settings' ); 
  3182. $locale = get_option( 'wcpgsk_locale', array() ); 
  3183.  
  3184. $wc_locale = $this->wcpgsk_get_country_locale(); 
  3185. $jsfields = $this->wcpgsk_get_country_locale_field_selectors(); 
  3186. $countrycodes = $this->wcpgsk_get_allowed_countries(); 
  3187. foreach($countrycodes as $countrycode => $cn) : 
  3188.  
  3189. $default_postcode = isset($locale['default']['postcode_before_city']) ? $locale['default']['postcode_before_city'] : '0'; 
  3190. $wc_localepostcode = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode]['postcode_before_city']) && $wc_locale[$countrycode]['postcode_before_city'] ? 1 : ( isset($wc_locale['default']['postcode_before_city']) && $wc_locale['default']['postcode_before_city'] ? 1 : $default_postcode ); 
  3191. $locale[$countrycode]['postcode_before_city'] = isset($locale[$countrycode]['postcode_before_city']) ? $locale[$countrycode]['postcode_before_city'] : $wc_localepostcode; 
  3192. $wc_locale[$countrycode]['postcode_before_city'] = $locale[$countrycode]['postcode_before_city'] ? true : false; 
  3193.  
  3194. foreach ($jsfields as $fieldkey => $config) : 
  3195. if ( isset($jsfields[$fieldkey]) && !empty($jsfields[$fieldkey]) ) : 
  3196. //use wcpgsk billing fields configuration 
  3197. if ( isset($options['checkoutform']['default_' . $fieldkey]) && $options['checkoutform']['default_' . $fieldkey] ) : 
  3198.  
  3199. $default_label = isset($locale['default']['label_' . $fieldkey]) ? $locale['default']['label_' . $fieldkey] : ''; 
  3200. $wc_localelabel = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$fieldkey]) && isset($wc_locale[$countrycode][$fieldkey]['label']) ? $wc_locale[$countrycode][$fieldkey]['label'] : ( isset($wc_locale['default'][$fieldkey]['label']) ? $wc_locale['default'][$fieldkey]['label'] : $default_label ); 
  3201. $locale[$countrycode]['label_' . $fieldkey] = isset($locale[$countrycode]['label_' . $fieldkey]) ? $locale[$countrycode]['label_' . $fieldkey] : $wc_localelabel; 
  3202. $wc_locale[$countrycode][$fieldkey]['label'] = __($locale[$countrycode]['label_' . $fieldkey], WCPGSK_DOMAIN); 
  3203.  
  3204. $default_placeholder = isset($locale['default']['placeholder_' . $fieldkey]) ? $locale['default']['placeholder_' . $fieldkey] : ''; 
  3205. $wc_localeplaceholder = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$fieldkey]) && isset($wc_locale[$countrycode][$fieldkey]['placeholder']) ? $wc_locale[$countrycode][$fieldkey]['placeholder'] : ( isset($wc_locale['default'][$fieldkey]['placeholder']) ? $wc_locale['default'][$fieldkey]['placeholder'] : $default_placeholder ); 
  3206. $locale[$countrycode]['placeholder_' . $fieldkey] = isset($locale[$countrycode]['placeholder_' . $fieldkey]) ? $locale[$countrycode]['placeholder_' . $fieldkey] : $wc_localeplaceholder; 
  3207. $wc_locale[$countrycode][$fieldkey]['placeholder'] = __($locale[$countrycode]['placeholder_' . $fieldkey], WCPGSK_DOMAIN); 
  3208.  
  3209. $default_required = isset($locale['default']['required_' . $fieldkey]) ? $locale['default']['required_' . $fieldkey] : '0'; 
  3210. $wc_localerequired = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$fieldkey]) && isset($wc_locale[$countrycode][$fieldkey]['required']) ? ( $wc_locale[$countrycode][$fieldkey]['required'] ? '1' : '0' ) : ( isset($wc_locale['default'][$fieldkey]['required']) && $wc_locale['default'][$fieldkey]['required'] ? '1' : $default_required ); 
  3211. $locale[$countrycode]['required_' . $fieldkey] = isset($locale[$countrycode]['required_' . $fieldkey]) ? $locale[$countrycode]['required_' . $fieldkey] : $wc_localerequired; 
  3212. $wc_locale[$countrycode][$fieldkey]['required'] = $locale[$countrycode]['required_' . $fieldkey] == '1' ? true : false; 
  3213.  
  3214. $default_hidden = isset($locale['default']['hidden_' . $fieldkey]) ? $locale['default']['hidden_' . $fieldkey] : '0'; 
  3215. $wc_localehidden = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$fieldkey]) && isset($wc_locale[$countrycode][$fieldkey]['hidden']) ? ( $wc_locale[$countrycode][$fieldkey]['hidden'] ? '1' : '0' ) : ( isset($wc_locale['default'][$fieldkey]['hidden']) && $wc_locale['default'][$fieldkey]['hidden'] ? '1' : $default_hidden ); 
  3216. $locale[$countrycode]['hidden_' . $fieldkey] = isset($locale[$countrycode]['hidden_' . $fieldkey]) ? $locale[$countrycode]['hidden_' . $fieldkey] : $wc_localehidden; 
  3217. $wc_locale[$countrycode][$fieldkey]['hidden'] = $locale[$countrycode]['hidden_' . $fieldkey] == '1' ? true : false; 
  3218.  
  3219. else : 
  3220. $wc_locale[$countrycode][$fieldkey]['required'] = false;  
  3221. if (isset($options['woofields']['required_billing_' . $fieldkey]) && $options['woofields']['required_billing_' . $fieldkey] == 1) : 
  3222. $wc_locale[$countrycode][$fieldkey]['required'] = true; 
  3223. else : 
  3224. $wc_locale[$countrycode][$fieldkey]['required'] = false;  
  3225. endif; 
  3226. if (isset($options['woofields']['remove_billing_' . $fieldkey]) && $options['woofields']['remove_billing_' . $fieldkey] == 1) : 
  3227. $wc_locale[$countrycode][$fieldkey]['required'] = false; 
  3228. $wc_locale[$countrycode][$fieldkey]['hidden'] = true; 
  3229. endif; 
  3230. if ( isset($options['woofields']['label_billing_' . $fieldkey]) ) : 
  3231. $wc_locale[$countrycode][$fieldkey]['label'] = __($options['woofields']['label_billing_' . $fieldkey], WCPGSK_DOMAIN); 
  3232. endif; 
  3233. if ( isset($options['woofields']['placeholder_billing_' . $fieldkey]) ) : 
  3234. $wc_locale[$countrycode][$fieldkey]['placeholder'] = __($options['woofields']['placeholder_billing_' . $fieldkey], WCPGSK_DOMAIN); 
  3235. endif; 
  3236.  
  3237. endif; 
  3238.  
  3239. endif; 
  3240. endforeach; 
  3241. endforeach; 
  3242.  
  3243. if ( function_exists('WC') ) : 
  3244. return array( 
  3245. 'locale' => json_encode( $wc_locale ),  
  3246. 'locale_fields' => json_encode( WC()->countries->get_country_locale_field_selectors() ),  
  3247. 'i18n_required_text' => esc_attr__( 'required', 'woocommerce' ),  
  3248. );  
  3249. else : 
  3250. //locale fields exist hardcoded in wc js file for WC versions below 2.1 
  3251. $params['locale'] = json_encode( $wc_locale ); 
  3252. return $params;  
  3253. endif; 
  3254.  
  3255. /** 
  3256. * Handle WooCommerce js overwrites of field labels, placeholders, hidden and required status. 
  3257. *  
  3258. * @access public 
  3259. * @param array $locale_fields 
  3260. * @since 1.7.1 
  3261. * @return array $locale_fields 
  3262. */  
  3263. public function wcpgsk_country_locale_field_selectors($locale_fields) { 
  3264. $options = get_option('wcpgsk_settings'); 
  3265. foreach($locale_fields as $field => $selectors) : 
  3266. $selarray = array(); 
  3267. if ( isset($options['checkoutform']['default_' . $field]) && $options['checkoutform']['default_' . $field] ) : 
  3268. $selarray[] = '#billing_' . $field . '_field'; 
  3269. $selarray[] = '#shipping_' . $field . '_field';  
  3270. else : 
  3271. $selarray[] = '#no_wc_billing_' . $field . '_handle'; 
  3272. $selarray[] = '#no_wc_shipping_' . $field . '_handle'; 
  3273. endif; 
  3274. $locale_fields[$field] = implode(', ', $selarray); 
  3275. endforeach; 
  3276. return $locale_fields; 
  3277.  
  3278. /** 
  3279. * Our filter for billing fields. 
  3280. * @access public 
  3281. * @param array $fields 
  3282. * @since 1.1.0 
  3283. * @modified 1.7.1 
  3284. * @return array $fields (processed) 
  3285. */  
  3286. public function wcpgsk_checkout_fields_billing($fields) { 
  3287. global $woocommerce; 
  3288. $options = get_option( 'wcpgsk_settings' ); 
  3289.  
  3290. $field_order = 1;  
  3291.  
  3292. $orderfields = array(); 
  3293. $lastClass = array(); 
  3294. foreach ($fields['billing'] as $key => $field) { 
  3295. if (isset($options['woofields']['remove_' . $key]) && $options['woofields']['remove_' . $key] == 1) { 
  3296. if ( $key == 'billing_country' ) : 
  3297. $countries = $woocommerce->countries->get_allowed_countries(); 
  3298. if ( isset( $countries ) && is_array( $countries ) && count( $countries ) == 1 ) : 
  3299. $fields['billing'][$key]['class'] = array('hidecountry'); 
  3300. elseif ( isset( $countries ) && is_array( $countries ) && count( $countries ) > 2 ) : 
  3301. //incorrect admin setting, do nothing 
  3302. endif;  
  3303. else : 
  3304. unset($fields['billing'][$key]);  
  3305. endif; 
  3306. else { 
  3307.  
  3308. $orderfields[$key] = $fields['billing'][$key]; 
  3309.  
  3310. if ( isset($options['woofields']['settings_' . $key]) && $options['woofields']['settings_' . $key]) : 
  3311. $orderfields[$key] = $this->createCustomStandardField($key, 'billing', $options['woofields']['type_' . $key]); 
  3312. endif; 
  3313.  
  3314. //cosmetic stuff 
  3315. if (!empty($options['woofields']['class_' . $key])) { 
  3316. if (!empty($orderfields[$key]['class']) && is_array($orderfields[$key]['class'])) 
  3317. $orderfields[$key]['class'][0] = $options['woofields']['class_' . $key]; 
  3318. else 
  3319. $orderfields[$key]['class'] = array ($options['woofields']['class_' . $key]); 
  3320.  
  3321. //Respect WC handling if desired 
  3322. $wc_field_handle = str_replace('billing_', '', $key);  
  3323. if ( isset($options['checkoutform']['default_' . $wc_field_handle]) && $options['checkoutform']['default_' . $wc_field_handle] ) : 
  3324. //do nothing with required 
  3325. $orderfields[$key]['label'] = !empty($options['woofields']['label_' . $key]) ? __($options['woofields']['label_' . $key], WCPGSK_DOMAIN) : ''; 
  3326. $orderfields[$key]['placeholder'] = !empty($options['woofields']['placeholder_' . $key]) ? __($options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN) : ''; 
  3327. else :  
  3328. $orderfields[$key]['label'] = !empty($options['woofields']['label_' . $key]) ? __($options['woofields']['label_' . $key], WCPGSK_DOMAIN) : ''; 
  3329.  
  3330. if (isset($options['woofields']['required_' . $key]) && $options['woofields']['required_' . $key] != 1) : 
  3331. $orderfields[$key]['required'] = false; 
  3332. elseif (isset($options['woofields']['required_' . $key]) && $options['woofields']['required_' . $key] == 1) : 
  3333. $orderfields[$key]['required'] = true; 
  3334. else : 
  3335. $orderfields[$key]['required'] = false;  
  3336. endif; 
  3337. $orderfields[$key]['placeholder'] = !empty($options['woofields']['placeholder_' . $key]) ? __($options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN) : ''; 
  3338. endif; 
  3339. //set the order data 
  3340.  
  3341.  
  3342. if (empty($options['woofields']['order_' . $key]) || !ctype_digit($options['woofields']['order_' . $key])) { 
  3343. $orderfields[$key]['order'] = $field_order; 
  3344. else { 
  3345. $orderfields[$key]['order'] = $options['woofields']['order_' . $key]; 
  3346. if ( isset($options['woofields']['settings_' . $key]) && $options['woofields']['settings_' . $key]) : 
  3347. $params = $this->explodeParameters($options['woofields']['settings_' . $key]); 
  3348. //if ( strpos($key, '_wcpgsk_repeater') !== false ) : 
  3349. //$testkey = str_replace('_wcpgsk_repeater', '', $key); 
  3350. //if ( !empty($options['woofields']['settings_' . $testkey]) ) : 
  3351. if ( is_array($params) && !empty($params) && isset($params['repeat_field']) && $params['repeat_field'] == '1' ) : 
  3352. $repkey = $key . '_wcpgsk_repeater'; 
  3353.  
  3354. $orderfields[$repkey] = $this->createCustomStandardFieldClone($key, 'billing', $options['woofields']['type_' . $key]); 
  3355.  
  3356. //set all our other data 
  3357. //unset required for repeater fields as this collides with WooCommerce 
  3358. if ( isset($orderfields[$repkey]['required']) ) unset($orderfields[$repkey]['required']); 
  3359. //check if repeater field 
  3360.  
  3361. $orderfields[$repkey]['placeholder'] = !empty($options['woofields']['placeholder_' . $key]) ? __($options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN) : ''; 
  3362. //set the order data 
  3363.  
  3364.  
  3365. if (empty($options['woofields']['order_' . $key]) || !ctype_digit($options['woofields']['order_' . $key])) { 
  3366. $orderfields[$repkey]['order'] = $field_order + 0.5; 
  3367. else { 
  3368. $orderfields[$repkey]['order'] = intval($options['woofields']['order_' . $key]) + 0.5; 
  3369. endif; 
  3370. endif; 
  3371. unset($fields['billing'][$key]); 
  3372. $field_order++; 
  3373. //order the fields 
  3374. uasort($orderfields, array($this, "compareFieldOrder"));  
  3375.  
  3376. //add the fields again 
  3377. foreach ($orderfields as $key => $field) { 
  3378. if ($key == 'order') 
  3379. unset($field['order']); 
  3380. else 
  3381. $fields['billing'][$key] = $field; 
  3382. return $fields; 
  3383.  
  3384. /** 
  3385. * Our filter for shipping fields. 
  3386. * @access public 
  3387. * @param array $fields 
  3388. * @since 1.1.0 
  3389. * @return array $fields (processed) 
  3390. */  
  3391. public function wcpgsk_checkout_fields_shipping($fields) { 
  3392. global $woocommerce; 
  3393. $options = get_option( 'wcpgsk_settings' ); 
  3394.  
  3395. $field_order = 1;  
  3396.  
  3397. $orderfields = array(); 
  3398.  
  3399. foreach ($fields['shipping'] as $key => $field) { 
  3400. if (isset($options['woofields']['remove_' . $key]) && $options['woofields']['remove_' . $key] == 1) { 
  3401. if ( $key == 'shipping_country' ) : 
  3402. $countries = $woocommerce->countries->get_shipping_countries(); 
  3403. if ( isset( $countries ) && is_array( $countries ) && count( $countries ) == 1 ) : 
  3404. $fields['shipping'][$key]['class'] = array('hidecountry'); 
  3405. elseif ( isset( $countries ) && is_array( $countries ) && count( $countries ) > 2 ) : 
  3406. //incorrect admin setting, do nothing 
  3407. endif;  
  3408. else : 
  3409. unset($fields['shipping'][$key]); 
  3410. endif; 
  3411. else { 
  3412.  
  3413. $orderfields[$key] = $fields['shipping'][$key]; 
  3414.  
  3415. //cosmetic stuff 
  3416. if (!empty($options['woofields']['class_' . $key])) { 
  3417. if (!empty($orderfields[$key]['class']) && is_array($orderfields[$key]['class'])) 
  3418. $orderfields[$key]['class'][0] = $options['woofields']['class_' . $key]; 
  3419. else 
  3420. $orderfields[$key]['class'] = array ($options['woofields']['class_' . $key]); 
  3421.  
  3422. //Respect WC handling if desired 
  3423. $wc_field_handle = str_replace('shipping_', '', $key);  
  3424. if ( isset($options['checkoutform']['default_' . $wc_field_handle]) && $options['checkoutform']['default_' . $wc_field_handle] ) : 
  3425. //do nothing with required 
  3426. $orderfields[$key]['label'] = !empty($options['woofields']['label_' . $key]) ? __($options['woofields']['label_' . $key], WCPGSK_DOMAIN) : ''; 
  3427. $orderfields[$key]['placeholder'] = !empty($options['woofields']['placeholder_' . $key]) ? __($options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN) : ''; 
  3428. else :  
  3429. $orderfields[$key]['label'] = !empty($options['woofields']['label_' . $key]) ? __($options['woofields']['label_' . $key], WCPGSK_DOMAIN) : ''; 
  3430. if (isset($options['woofields']['required_' . $key]) && $options['woofields']['required_' . $key] != 1) : 
  3431. $orderfields[$key]['required'] = false; 
  3432. elseif (isset($options['woofields']['required_' . $key]) && $options['woofields']['required_' . $key] == 1) : 
  3433. $orderfields[$key]['required'] = true; 
  3434. else : 
  3435. $orderfields[$key]['required'] = false;  
  3436. endif; 
  3437. $orderfields[$key]['placeholder'] = !empty($options['woofields']['placeholder_' . $key]) ? __($options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN) : ''; 
  3438. endif; 
  3439.  
  3440. //set the order data 
  3441.  
  3442.  
  3443. if (empty($options['woofields']['order_' . $key]) || !ctype_digit($options['woofields']['order_' . $key])) { 
  3444. $orderfields[$key]['order'] = $field_order; 
  3445. else { 
  3446. $orderfields[$key]['order'] = $options['woofields']['order_' . $key]; 
  3447.  
  3448. if ( isset($options['woofields']['settings_' . $key]) && $options['woofields']['settings_' . $key]) : 
  3449. $params = $this->explodeParameters($options['woofields']['settings_' . $key]); 
  3450. //if ( strpos($key, '_wcpgsk_repeater') !== false ) : 
  3451. //$testkey = str_replace('_wcpgsk_repeater', '', $key); 
  3452. //if ( !empty($options['woofields']['settings_' . $testkey]) ) : 
  3453. if ( is_array($params) && !empty($params) && isset($params['repeat_field']) && $params['repeat_field'] == '1' ) : 
  3454. $repkey = $key . '_wcpgsk_repeater'; 
  3455.  
  3456. $orderfields[$repkey] = $this->createCustomStandardFieldClone($key, 'shipping', $options['woofields']['type_' . $key]); 
  3457.  
  3458. //set all our other data 
  3459. //woocommerce changed? 
  3460. //unset required for repeater fields as this collides with WooCommerce 
  3461. if ( isset($orderfields[$repkey]['required']) ) unset($orderfields[$repkey]['required']); 
  3462. //check if repeater field 
  3463.  
  3464. $orderfields[$repkey]['placeholder'] = !empty($options['woofields']['placeholder_' . $key]) ? __($options['woofields']['placeholder_' . $key], WCPGSK_DOMAIN) : ''; 
  3465. //set the order data 
  3466.  
  3467.  
  3468. if (empty($options['woofields']['order_' . $key]) || !ctype_digit($options['woofields']['order_' . $key])) { 
  3469. $orderfields[$repkey]['order'] = $field_order + 0.5; 
  3470. else { 
  3471. $orderfields[$repkey]['order'] = intval($options['woofields']['order_' . $key]) + 0.5; 
  3472. endif; 
  3473. endif; 
  3474. unset($fields['shipping'][$key]); 
  3475. $field_order++; 
  3476. //order the fields 
  3477. uasort($orderfields, array($this, "compareFieldOrder"));  
  3478.  
  3479. //add the fields again 
  3480. foreach ($orderfields as $key => $field) { 
  3481. if ($key == 'order') 
  3482. unset($field['order']); 
  3483. else 
  3484. $fields['shipping'][$key] = $field; 
  3485. return $fields; 
  3486.  
  3487.  
  3488. /** 
  3489. * Process form data supplied via the checkout form. 
  3490. * @access public 
  3491. * @since 1.1.0 
  3492. * @modified 1.7.1 
  3493. * @return Raise errors and adjust values if necessary 
  3494. */  
  3495. public function wcpgsk_checkout_process() { 
  3496. global $woocommerce; 
  3497. global $wcpgsk_session; 
  3498. if ( function_exists('WC') ) : 
  3499. WC()->session->set('post', $_POST); 
  3500. else : 
  3501. $wcpgsk_session->post = $_POST; 
  3502. endif; 
  3503.  
  3504. //$wcpgsk_session->post = $_POST; 
  3505.  
  3506. $options = get_option( 'wcpgsk_settings' ); 
  3507.  
  3508. //do_action('wcpgsk_checkout_process_action'); 
  3509. if ( !is_user_logged_in() ) : 
  3510. if (isset($options['checkoutform']['billingemailvalidator']) && $options['checkoutform']['billingemailvalidator'] == 1) { 
  3511. if ($_POST[ 'billing_email' ] && $_POST[ 'billing_email_validator' ] && strtolower($_POST[ 'billing_email' ]) != strtolower($_POST[ 'billing_email_validator' ])) 
  3512. wcpgsk_add_error( '<strong>' . __('Email addresses do not match', WCPGSK_DOMAIN) . ': ' . $_POST[ 'billing_email' ] . ' : ' . (empty($_POST[ 'billing_email_validator' ]) ? __('Missing validation email', WCPGSK_DOMAIN) : $_POST[ 'billing_email_validator' ]) . '</strong>'); 
  3513. elseif ($_POST[ 'billing_email' ] && !$_POST[ 'billing_email_validator' ]) 
  3514. wcpgsk_add_error( '<strong>' . __('You have to supply a validation email for: ', WCPGSK_DOMAIN) . $_POST[ 'billing_email' ] . '</strong>'); 
  3515. endif; 
  3516. //Just communicate the required state to WC plus the label in billing context based on user choice and locale configuration 
  3517. //WC will take care of the error handling 
  3518. if ( isset($_POST['billing_country']) && $_POST['billing_country'] ) : 
  3519. //Respect WC handling if desired 
  3520. $jsfields = $this->wcpgsk_get_country_locale_field_selectors(); 
  3521. $locale = get_option( 'wcpgsk_locale', array() ); 
  3522. $wc_locale = $this->wcpgsk_get_country_locale(); 
  3523. $countrycode = $_POST['billing_country']; 
  3524. foreach ($jsfields as $wc_field_handle => $wc_field_config) : 
  3525. if ( isset($options['checkoutform']['default_' . $wc_field_handle]) && $options['checkoutform']['default_' . $wc_field_handle] ) : 
  3526. $default_required = isset($locale['default']['required_' . $wc_field_handle]) ? $locale['default']['required_' . $wc_field_handle] : '0'; 
  3527. $wc_localerequired = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$wc_field_handle]) && isset($wc_locale[$countrycode][$wc_field_handle]['required']) ? ( $wc_locale[$countrycode][$wc_field_handle]['required'] ? '1' : '0' ) : ( isset($wc_locale['default'][$wc_field_handle]['required']) && $wc_locale['default'][$wc_field_handle]['required'] ? '1' : $default_required ); 
  3528. $locale[$countrycode]['required_' . $wc_field_handle] = isset($locale[$countrycode]['required_' . $wc_field_handle]) ? $locale[$countrycode]['required_' . $wc_field_handle] : $wc_localerequired; 
  3529. $required_field = $locale[$countrycode]['required_' . $wc_field_handle] ? true : false; 
  3530.  
  3531. $default_label = isset($locale['default']['label_' . $wc_field_handle]) ? $locale['default']['label_' . $wc_field_handle] : ''; 
  3532. $wc_localelabel = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$wc_field_handle]) && isset($wc_locale[$countrycode][$wc_field_handle]['label']) ? $wc_locale[$countrycode][$wc_field_handle]['label'] : ( isset($wc_locale['default'][$wc_field_handle]['label']) ? $wc_locale['default'][$wc_field_handle]['label'] : $default_label );  
  3533. $locale[$countrycode]['label_' . $wc_field_handle] = isset($locale[$countrycode]['label_' . $wc_field_handle]) ? $locale[$countrycode]['label_' . $wc_field_handle] : $wc_localelabel; 
  3534. $required_label = $locale[$countrycode]['label_' . $wc_field_handle]; 
  3535.  
  3536. $woocommerce->checkout->checkout_fields['billing']['billing_' . $wc_field_handle]['required'] = $required_field; 
  3537. $woocommerce->checkout->checkout_fields['billing']['billing_' . $wc_field_handle]['label'] = __($required_label, WCPGSK_DOMAIN); 
  3538.  
  3539. endif; 
  3540. endforeach; 
  3541. endif; 
  3542.  
  3543. //Just communicate the required state to WC plus the label in shipping context based on user choice and locale configuration 
  3544. //WC will take care of the error handling 
  3545. if ( isset($_POST['shipping_country']) && $_POST['shipping_country'] ) : 
  3546. //Respect WC handling if desired 
  3547. $jsfields = $this->wcpgsk_get_country_locale_field_selectors(); 
  3548. $locale = get_option( 'wcpgsk_locale', array() ); 
  3549. $wc_locale = $this->wcpgsk_get_country_locale(); 
  3550. $countrycode = $_POST['shipping_country']; 
  3551. foreach ($jsfields as $wc_field_handle => $wc_field_config) : 
  3552. if ( isset($options['checkoutform']['default_' . $wc_field_handle]) && $options['checkoutform']['default_' . $wc_field_handle] ) : 
  3553. $default_required = isset($locale['default']['required_' . $wc_field_handle]) ? $locale['default']['required_' . $wc_field_handle] : '0'; 
  3554. $wc_localerequired = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$wc_field_handle]) && isset($wc_locale[$countrycode][$wc_field_handle]['required']) ? ( $wc_locale[$countrycode][$wc_field_handle]['required'] ? '1' : '0' ) : ( isset($wc_locale['default'][$wc_field_handle]['required']) && $wc_locale['default'][$wc_field_handle]['required'] ? '1' : $default_required ); 
  3555. $locale[$countrycode]['required_' . $wc_field_handle] = isset($locale[$countrycode]['required_' . $wc_field_handle]) ? $locale[$countrycode]['required_' . $wc_field_handle] : $wc_localerequired; 
  3556. $required_field = $locale[$countrycode]['required_' . $wc_field_handle] == '1' ? true : false; 
  3557.  
  3558. $default_label = isset($locale['default']['label_' . $wc_field_handle]) ? $locale['default']['label_' . $wc_field_handle] : ''; 
  3559. $wc_localelabel = isset($wc_locale[$countrycode]) && isset($wc_locale[$countrycode][$wc_field_handle]) && isset($wc_locale[$countrycode][$wc_field_handle]['label']) ? $wc_locale[$countrycode][$wc_field_handle]['label'] : ( isset($wc_locale['default'][$wc_field_handle]['label']) ? $wc_locale['default'][$wc_field_handle]['label'] : $default_label );  
  3560. $locale[$countrycode]['label_' . $wc_field_handle] = isset($locale[$countrycode]['label_' . $wc_field_handle]) ? $locale[$countrycode]['label_' . $wc_field_handle] : $wc_localelabel; 
  3561. $required_label = $locale[$countrycode]['label_' . $wc_field_handle]; 
  3562.  
  3563. $woocommerce->checkout->checkout_fields['shipping']['shipping_' . $wc_field_handle]['required'] = $required_field; 
  3564. $woocommerce->checkout->checkout_fields['shipping']['shipping_' . $wc_field_handle]['label'] = __($required_label, WCPGSK_DOMAIN); 
  3565. endif; 
  3566. endforeach; 
  3567. endif; 
  3568.  
  3569. $combine = array(); 
  3570. foreach($_POST as $key => $val) { 
  3571. if ( strpos($key, '_wcpgsk_repeater') !== false ) : 
  3572. $testkey = str_replace('_wcpgsk_repeater', '', $key); 
  3573. if ( $_POST[$key] != $_POST[$testkey] ) : 
  3574. $captured_value = $_POST[ $testkey ]; 
  3575. if ( isset($options['woofields']['settings_' . $testkey]) ) : 
  3576. $params = $this->explodeParameters($options['woofields']['settings_' . $testkey]); 
  3577. if ( isset($params) && isset($params['validate']) && !empty($params['validate']) && $params['validate'] == 'password' ) : 
  3578. $captured_value = '*******'; 
  3579. endif; 
  3580. endif; 
  3581. $forLabel = ''; 
  3582. if ( isset($options['woofields']['label_' . $testkey]) && !empty($options['woofields']['label_' . $testkey]) ) : 
  3583. $forLabel = __($options['woofields']['label_' . $testkey], WCPGSK_DOMAIN); 
  3584. endif; 
  3585. wcpgsk_add_error( '<strong>' . sprintf(__('You have to validate the value <em style="color:red">%s</em> for %s correctly! Please check your input.', WCPGSK_DOMAIN), $captured_value, $forLabel ) . '</strong>'); 
  3586.  
  3587. endif; 
  3588. unset($_POST[$key]); 
  3589.  
  3590. elseif ( ( isset($options['woofields']['billing'][$key]['custom_' . $key]) && $options['woofields']['billing'][$key]['custom_' . $key] ) || ( isset( $options['woofields']['shipping'][$key]['custom_' . $key] ) && $options['woofields']['shipping'][$key]['custom_' . $key] ) ) : 
  3591. if ( $options['woofields']['type_' . $key] == 'date' && !empty($_POST[$key]) ) : 
  3592. //transform back based on field setting 
  3593. $params = $this->explodeParameters($options['woofields']['settings_' . $key]); 
  3594. $_POST[$key] = str_replace('-', '/', $_POST[$key]); 
  3595. if ( isset($params['dateformat']) && !empty($params['dateformat']) ) : 
  3596. if ( $params['dateformat'] == 'dd/mm/yy' ) : 
  3597. $arrdate = explode('/', $_POST[$key]); 
  3598. $_POST[$key] = $arrdate[2].'/'.$arrdate[1].'/'.$arrdate[0]; 
  3599. elseif ( $params['dateformat'] == 'mm/dd/yy' ) : 
  3600. $arrdate = explode('/', $_POST[$key]); 
  3601. $_POST[$key] = $arrdate[2].'/'.$arrdate[0].'/'.$arrdate[1];  
  3602. endif; 
  3603. endif; 
  3604. if ( $this->ValidateDate($_POST[$key]) ) : 
  3605. if ( isset($params) && isset($params['mindays']) && !empty($params['mindays']) && ( ctype_digit( strval( $params['mindays'] ) ) || is_numeric( strval( $params['mindays'] ) ) ) ) :  
  3606. $forLabel = ''; 
  3607. $daydiff = $this->datediffdays($_POST[$key]); 
  3608. if ( $params['mindays'] < 0 ) : 
  3609. if ( $daydiff < $params['mindays'] ) : 
  3610. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  3611. $forLabel = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  3612. endif; 
  3613. $mindate = date('Y/m/d', strtotime(date("Y-m-d") . ' - ' . ( absint( $params['mindays'] ) - 1 ) . ' days')); 
  3614. wcpgsk_add_error( '<strong>' . sprintf(__('Date value for <em style="color:red">%s</em> has to be set at least to <em>%s</em>!', WCPGSK_DOMAIN), $forLabel, $mindate ) . '</strong>');  
  3615. endif;  
  3616. else :  
  3617. if ( $daydiff < $params['mindays'] ) : 
  3618. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  3619. $forLabel = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  3620. endif; 
  3621. $mindate = date('Y/m/d', strtotime(date("Y-m-d") . ' + ' . $params['mindays'] . ' days')); 
  3622. wcpgsk_add_error( '<strong>' . sprintf(__('Date value for <em style="color:red">%s</em> has to be set at least to <em>%s</em>!', WCPGSK_DOMAIN), $forLabel, $mindate ) . '</strong>');  
  3623. endif; 
  3624. endif; 
  3625. elseif ( isset($params) && isset($params['mindays']) && !empty($params['mindays']) ) : 
  3626. $forLabel = ''; 
  3627. $mindays = $params['mindays']; 
  3628. if ( isset($params['dateformat']) && !empty($params['dateformat']) ) : 
  3629. if ( $params['dateformat'] == 'dd/mm/yy' ) : 
  3630. $arrdate = explode('/', $params['mindays']); 
  3631. $mindays = $arrdate[2].'/'.$arrdate[1].'/'.$arrdate[0]; 
  3632. elseif ( $params['dateformat'] == 'mm/dd/yy' ) : 
  3633. $arrdate = explode('/', $params['mindays']); 
  3634. $mindays = $arrdate[2].'/'.$arrdate[0].'/'.$arrdate[1];  
  3635. endif; 
  3636. endif; 
  3637.  
  3638. if ( $_POST[$key] < $mindays ) : 
  3639. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  3640. $forLabel = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  3641. endif; 
  3642. wcpgsk_add_error( '<strong>' . sprintf(__('Date value for <em style="color:red">%s</em> has to be set at least to <em>%s</em>!', WCPGSK_DOMAIN), $forLabel, $params['mindays'] ) . '</strong>');  
  3643. endif;  
  3644.  
  3645. endif; 
  3646. if ( isset($params) && isset($params['maxdays']) && !empty($params['maxdays']) && ( ctype_digit( strval( $params['maxdays'] ) ) || is_numeric( strval( $params['maxdays'] ) ) ) ) : 
  3647. $forLabel = ''; 
  3648. $daydiff = $this->datediffdays($_POST[$key]); 
  3649. if ( $params['maxdays'] < 0 ) : 
  3650. if ( $daydiff > $params['maxdays'] ) : 
  3651. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  3652. $forLabel = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  3653. endif; 
  3654. $maxdate = date('Y/m/d', strtotime(date("Y-m-d") . ' - ' . ( absint( $params['maxdays'] - 1 ) ) . ' days')); 
  3655. wcpgsk_add_error( '<strong>' . sprintf(__('Date value for <em style="color:red">%s</em> has to be priorrrr to <em>%s</em>!', WCPGSK_DOMAIN), $forLabel, $maxdate ) . '</strong>'); 
  3656. endif;  
  3657. else : 
  3658. if ( $daydiff > $params['maxdays'] ) : 
  3659. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  3660. $forLabel = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  3661. endif; 
  3662. $maxdate = date('Y/m/d', strtotime(date("Y-m-d") . ' + ' . ($params['maxdays'] + 1) . ' days')); 
  3663. wcpgsk_add_error( '<strong>' . sprintf(__('Date value for <em style="color:red">%s</em> has to be prior to <em>%s</em>!', WCPGSK_DOMAIN), $forLabel, $maxdate ) . '</strong>');  
  3664. endif; 
  3665. endif; 
  3666. elseif ( isset($params) && isset($params['maxdays']) && !empty($params['maxdays']) ) : 
  3667. $forLabel = ''; 
  3668. $maxdays = $params['maxdays']; 
  3669. if ( isset($params['dateformat']) && !empty($params['dateformat']) ) : 
  3670. if ( $params['dateformat'] == 'dd/mm/yy' ) : 
  3671. $arrdate = explode('/', $params['maxdays']); 
  3672. $maxdays = $arrdate[2].'/'.$arrdate[1].'/'.$arrdate[0]; 
  3673. elseif ( $params['dateformat'] == 'mm/dd/yy' ) : 
  3674. $arrdate = explode('/', $params['maxdays']); 
  3675. $maxdays = $arrdate[2].'/'.$arrdate[0].'/'.$arrdate[1];  
  3676. endif; 
  3677. endif; 
  3678.  
  3679. if ( $_POST[$key] > $maxdays ) : 
  3680. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  3681. $forLabel = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  3682. endif; 
  3683. wcpgsk_add_error( '<strong>' . sprintf(__('Date value for <em style="color:red">%s</em> has to be prior to <em>%s</em>!', WCPGSK_DOMAIN), $forLabel, $params['maxdays'] ) . '</strong>');  
  3684. endif;  
  3685. endif; 
  3686. else : 
  3687. $forLabel = ''; 
  3688. if ( isset($options['woofields']['label_' . $key]) && !empty($options['woofields']['label_' . $key]) ) : 
  3689. $forLabel = __($options['woofields']['label_' . $key], WCPGSK_DOMAIN); 
  3690. endif; 
  3691. wcpgsk_add_error( '<strong>' . sprintf(__('You have to supply a valid date for <em style="color:red">%s</em> using the format year/month/day, e.g. 2014/12/24', WCPGSK_DOMAIN), $forLabel ) . '</strong>');  
  3692. endif; 
  3693. elseif ( $options['woofields']['type_' . $key] == 'select' ) : 
  3694. //if ( is_array($key) ) : 
  3695. //endif; 
  3696.  
  3697. endif; 
  3698.  
  3699.  
  3700. $combine[$key] = array(); 
  3701. if (is_array($_POST[$key])) { 
  3702. foreach($_POST[$key] as $value) { 
  3703. $combine[$key][] = esc_attr($value); 
  3704. }  
  3705. else $combine[$key][] = esc_attr($val); 
  3706. endif; 
  3707. foreach($combine as $key => $val) { 
  3708. $_POST[$key] = implode('|', $val); 
  3709.  
  3710.  
  3711. function wcpgsk_checkout_update_order_meta( $order_id, $posted ) { 
  3712. global $woocommerce; 
  3713. global $wcpgsk_session; 
  3714. if ( function_exists('WC') ) : 
  3715. WC()->session->set('post', $_POST); 
  3716. else : 
  3717. $wcpgsk_session->post = $_POST; 
  3718. endif;  
  3719. $options = get_option( 'wcpgsk_settings' ); 
  3720. foreach($posted as $key => $val) : 
  3721. if ( ( isset($options['woofields']['billing'][$key]['custom_' . $key]) && $options['woofields']['billing'][$key]['custom_' . $key] ) || ( isset( $options['woofields']['shipping'][$key]['custom_' . $key] ) && $options['woofields']['shipping'][$key]['custom_' . $key] ) ) : 
  3722. if ( !isset( $options['woofields']['customeronly_' . $key] ) || ( isset( $options['woofields']['customeronly_' . $key] ) && $options['woofields']['customeronly_' . $key] == 0 ) ) : 
  3723. update_post_meta( $order_id, "_" . $key, $val ); 
  3724. endif; 
  3725. endif; 
  3726. endforeach; 
  3727.  
  3728. public function createCustomStandardField($customkey, $context, $type) { 
  3729. $options = get_option( 'wcpgsk_settings' ); 
  3730. $clear = false; 
  3731. $field = array(); 
  3732. if (isset($options['woofields'][$context]) && is_array($options['woofields'][$context])) { 
  3733. $params = $this->explodeParameters($options['woofields']['settings_' . $customkey]); 
  3734. $custom_attributes = array(); 
  3735. $seloptions = array(); 
  3736. $selected = null; 
  3737. $clear = $options['woofields']['class_' . $customkey] == 'form-row-last' ? true : false; 
  3738. $validate = array(); 
  3739. $display = ''; 
  3740. $default = ''; 
  3741. $class = array( $options['woofields']['class_' . $customkey] ); 
  3742. if ( isset( $options['checkoutform']['cssclass'] ) && !empty( $options['checkoutform']['cssclass'] ) ) : 
  3743. $class = array_merge( $class, array_map( "sanitize_html_class", explode( ' ', $options['checkoutform']['cssclass'] ) ) ); 
  3744. endif; 
  3745. if (is_array($params) && !empty($params)) { 
  3746. foreach($params as $key => $value) { 
  3747. switch($key) { 
  3748. //does not make much sense as validation class is not really available in woocommerce 
  3749. //we put this as a parameter 
  3750. case 'validate': 
  3751. if ( $value && $value == 'password' ) : 
  3752. $type = 'password'; 
  3753. $validate = array(); 
  3754. elseif ( !empty($value) ) : 
  3755. $custom_attributes[$key] = $value; 
  3756. $validate = array($value); 
  3757. endif; 
  3758. break; 
  3759. case 'options': 
  3760.  
  3761. foreach($value as $keyval => $option) { 
  3762. $seloptions[$keyval] = __($option, WCPGSK_DOMAIN); 
  3763. break; 
  3764. case 'selected': 
  3765. if ( !empty($value) ) : 
  3766. foreach($value as $keyval => $option) { 
  3767. //if (!empty($option) || $value == 0) $selected = $option; 
  3768. if (!empty($keyval)) $selected = $keyval; 
  3769. endif; 
  3770. break; 
  3771.  
  3772. case 'multiple': 
  3773. if ($value == 1) $custom_attributes[$key] = 'multiple'; 
  3774. break; 
  3775.  
  3776. case 'value': 
  3777. if (!empty($value) || $value === 0 || $value === '0') $default = $value; 
  3778. break; 
  3779.  
  3780. case 'repeat_field': 
  3781. //not necessary here? 
  3782. break; 
  3783. default: 
  3784. if (!empty($value) || $value === 0 || $value === '0') 
  3785. $custom_attributes[$key] = $value; 
  3786. $options['woofields']['label_' . $customkey] = !empty($options['woofields']['label_' . $customkey]) ? $options['woofields']['label_' . $customkey] : ''; 
  3787. $options['woofields']['placeholder_' . $customkey] = !empty($options['woofields']['placeholder_' . $customkey]) ? $options['woofields']['placeholder_' . $customkey] : ''; 
  3788. $options['woofields']['required_' . $customkey] = isset($options['woofields']['required_' . $customkey]) && $options['woofields']['required_' . $customkey] == 1 ? 1 : 0;  
  3789. switch($type) { 
  3790. case 'password': 
  3791. $custom_attributes['display'] = 'text'; 
  3792. $field = array( 
  3793. 'type' => 'password',  
  3794. 'label' => __( $options['woofields']['label_' . $customkey], WCPGSK_DOMAIN ),  
  3795. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3796. 'required' => (($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3797. 'custom_attributes' => $custom_attributes,  
  3798. 'class' => $class,  
  3799. 'validate' => $validate,  
  3800. 'clear' => $clear 
  3801. ); 
  3802. break; 
  3803.  
  3804. case 'text': 
  3805. $custom_attributes['display'] = 'text'; 
  3806. $field = array( 
  3807. 'type' => 'text',  
  3808. 'label' => __( $options['woofields']['label_' . $customkey], WCPGSK_DOMAIN ),  
  3809. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3810. 'required' => (($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3811. 'custom_attributes' => $custom_attributes,  
  3812. 'class' => $class,  
  3813. 'validate' => $validate,  
  3814. 'clear' => $clear 
  3815. ); 
  3816. break; 
  3817.  
  3818. case 'number': 
  3819. $custom_attributes['display'] = 'number'; 
  3820. $field = array( 
  3821. 'type' => 'text',  
  3822. 'label' => __( $options['woofields']['label_' . $customkey], WCPGSK_DOMAIN ),  
  3823. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3824. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3825. 'custom_attributes' => $custom_attributes,  
  3826. 'default' => $default,  
  3827. 'class' => $class,  
  3828. 'validate' => $validate,  
  3829. 'clear' => $clear 
  3830. ); 
  3831. break; 
  3832.  
  3833. case 'date': 
  3834. $custom_attributes['display'] = 'date'; 
  3835. $field = array( 
  3836. 'type' => 'text',  
  3837. 'label' => __( $options['woofields']['label_' . $customkey], WCPGSK_DOMAIN ),  
  3838. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3839. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3840. 'custom_attributes' => $custom_attributes,  
  3841. 'class' => $class,  
  3842. 'validate' => array('date'),  
  3843. 'clear' => $clear 
  3844. ); 
  3845. break; 
  3846.  
  3847. case 'time': 
  3848. $custom_attributes['display'] = 'time'; 
  3849.  
  3850. $field = array( 
  3851. 'type' => 'text',  
  3852. 'label' => __( $options['woofields']['label_' . $customkey], WCPGSK_DOMAIN ),  
  3853. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3854. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3855. 'custom_attributes' => $custom_attributes,  
  3856. 'class' => $class,  
  3857. 'validate' => array('time'),  
  3858. 'clear' => $clear 
  3859. ); 
  3860. break; 
  3861.  
  3862. case 'textarea': 
  3863. $custom_attributes['display'] = 'textarea'; 
  3864.  
  3865. $field = array( 
  3866. 'type' => 'textarea',  
  3867. 'label' => __( $options['woofields']['label_' . $customkey], WCPGSK_DOMAIN ),  
  3868. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3869. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3870. 'custom_attributes' => $custom_attributes,  
  3871. 'class' => $class,  
  3872. 'validate' => $validate,  
  3873. 'clear' => $clear 
  3874. ); 
  3875. break; 
  3876.  
  3877. case 'select': 
  3878. $custom_attributes['display'] = $display; 
  3879. $custom_attributes['hasselected'] = !empty($selected) ? 'true' : 'false'; 
  3880. $field = array( 
  3881. 'type' => 'select',  
  3882. 'label' => __( $options['woofields']['label_' . $customkey], WCPGSK_DOMAIN ),  
  3883. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3884. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3885. 'options' => $seloptions,  
  3886. 'default' => $selected,  
  3887. 'custom_attributes' => $custom_attributes,  
  3888. 'class' => $class,  
  3889. 'validate' => $validate,  
  3890. 'clear' => $clear  
  3891. ); 
  3892. break; 
  3893. default: 
  3894. $custom_attributes['display'] = $display; 
  3895. $field = array( 
  3896. 'type' => $type,  
  3897. 'label' => __( $options['woofields']['label_' . $customkey], WCPGSK_DOMAIN ),  
  3898. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3899. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3900. 'custom_attributes' => $custom_attributes,  
  3901. 'class' => $class,  
  3902. 'validate' => $validate,  
  3903. 'clear' => $clear 
  3904. );  
  3905. break; 
  3906. //apply_filters('wcpgsk_create_custom_standard_field', $field,  
  3907. return apply_filters('wcpgsk_create_custom_standard_field', $field); 
  3908.  
  3909. public function createCustomStandardFieldClone($customkey, $context, $type) { 
  3910. $options = get_option( 'wcpgsk_settings' ); 
  3911. $clear = false; 
  3912. $field = array(); 
  3913. if (isset($options['woofields'][$context]) && is_array($options['woofields'][$context])) { 
  3914. $params = $this->explodeParameters($options['woofields']['settings_' . $customkey]); 
  3915. $custom_attributes = array(); 
  3916. $seloptions = array(); 
  3917. $selected = null; 
  3918. $clear = $options['woofields']['class_' . $customkey] == 'form-row-first' ? true : false; 
  3919. $validate = array(); 
  3920. $display = ''; 
  3921. $default = ''; 
  3922.  
  3923. if (is_array($params) && !empty($params)) { 
  3924. foreach($params as $key => $value) { 
  3925. switch($key) { 
  3926. //does not make much sense as validation class is not really available in woocommerce 
  3927. //we put this as a parameter 
  3928. case 'validate': 
  3929. if ( $value && $value == 'password' ) : 
  3930. $type = 'password'; 
  3931. $validate = array(); 
  3932. elseif ( !empty($value) ) : 
  3933. $custom_attributes[$key] = $value; 
  3934. $validate = array($value); 
  3935. endif; 
  3936. break; 
  3937. case 'options': 
  3938.  
  3939. foreach($value as $keyval => $option) { 
  3940. $seloptions[$keyval] = __($option, WCPGSK_DOMAIN); 
  3941. break; 
  3942. case 'selected': 
  3943. if ( !empty($value) ) : 
  3944. foreach($value as $keyval => $option) { 
  3945. //if (!empty($option) || $value == 0) $selected = $option; 
  3946. if (!empty($keyval)) $selected = $keyval; 
  3947. endif; 
  3948. break; 
  3949.  
  3950. case 'multiple': 
  3951. if ($value == 1) $custom_attributes[$key] = 'multiple'; 
  3952. break; 
  3953.  
  3954. case 'value': 
  3955. if (!empty($value) || $value === 0 || $value === '0') $default = $value; 
  3956. break; 
  3957.  
  3958. default: 
  3959. if (!empty($value) || $value === 0 || $value === '0') 
  3960. $custom_attributes[$key] = $value; 
  3961. //$options['woofields']['label_' . $customkey] = !empty($options['woofields']['label_' . $customkey]) ? $options['woofields']['label_' . $customkey] : ''; 
  3962. $options['woofields']['placeholder_' . $customkey] = !empty($options['woofields']['placeholder_' . $customkey]) ? $options['woofields']['placeholder_' . $customkey] : ''; 
  3963. $options['woofields']['required_' . $customkey] = isset($options['woofields']['required_' . $customkey]) && $options['woofields']['required_' . $customkey] == 1 ? 1 : 0;  
  3964. $clone_class = array( 'form-row-wide' ); 
  3965. if ($options['woofields']['class_' . $customkey] == 'form-row-first') $clone_class = array( 'form-row-last' ); 
  3966.  
  3967. if ( isset( $options['checkoutform']['cssclass'] ) && !empty( $options['checkoutform']['cssclass'] ) ) : 
  3968. $clone_class = array_merge( $clone_class, array_map( "sanitize_html_class", explode( ' ', $options['checkoutform']['cssclass'] ) ) ); 
  3969. endif; 
  3970.  
  3971. $clone_label = __('Repeat value', WCPGSK_DOMAIN); 
  3972.  
  3973. switch($type) { 
  3974. case 'password': 
  3975. $custom_attributes['display'] = 'text'; 
  3976. $field = array( 
  3977. 'type' => 'password',  
  3978. 'label' => $clone_label,  
  3979. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3980. 'required' => (($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3981. 'custom_attributes' => $custom_attributes,  
  3982. 'class' => $clone_class,  
  3983. 'validate' => $validate,  
  3984. 'clear' => $clear 
  3985. ); 
  3986. break; 
  3987. case 'text': 
  3988. $custom_attributes['display'] = 'text'; 
  3989. $field = array( 
  3990. 'type' => 'text',  
  3991. 'label' => $clone_label,  
  3992. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  3993. 'required' => (($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  3994. 'custom_attributes' => $custom_attributes,  
  3995. 'class' => $clone_class,  
  3996. 'validate' => $validate,  
  3997. 'clear' => $clear 
  3998. ); 
  3999. break; 
  4000.  
  4001. case 'number': 
  4002. $custom_attributes['display'] = 'number'; 
  4003. $field = array( 
  4004. 'type' => 'text',  
  4005. 'label' => $clone_label,  
  4006. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  4007. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  4008. 'custom_attributes' => $custom_attributes,  
  4009. 'default' => $default,  
  4010. 'class' => $clone_class,  
  4011. 'validate' => $validate,  
  4012. 'clear' => $clear 
  4013. ); 
  4014. break; 
  4015.  
  4016. case 'date': 
  4017. $custom_attributes['display'] = 'date'; 
  4018. $field = array( 
  4019. 'type' => 'text',  
  4020. 'label' => $clone_label,  
  4021. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  4022. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  4023. 'custom_attributes' => $custom_attributes,  
  4024. 'class' => $clone_class,  
  4025. 'validate' => array('date'),  
  4026. 'clear' => $clear 
  4027. ); 
  4028. break; 
  4029.  
  4030. case 'time': 
  4031. $custom_attributes['display'] = 'time'; 
  4032.  
  4033. $field = array( 
  4034. 'type' => 'text',  
  4035. 'label' => $clone_label,  
  4036. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  4037. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  4038. 'custom_attributes' => $custom_attributes,  
  4039. 'class' => $clone_class,  
  4040. 'validate' => array('time'),  
  4041. 'clear' => $clear 
  4042. ); 
  4043. break; 
  4044.  
  4045. case 'textarea': 
  4046. $custom_attributes['display'] = 'textarea'; 
  4047.  
  4048. $field = array( 
  4049. 'type' => 'textarea',  
  4050. 'label' => $clone_label,  
  4051. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  4052. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  4053. 'custom_attributes' => $custom_attributes,  
  4054. 'class' => $clone_class,  
  4055. 'validate' => $validate,  
  4056. 'clear' => $clear 
  4057. ); 
  4058. break; 
  4059.  
  4060. case 'select': 
  4061. $custom_attributes['display'] = $display; 
  4062. $field = array( 
  4063. 'type' => 'select',  
  4064. 'label' => $clone_label,  
  4065. 'placeholder' => __( $options['woofields']['placeholder_' . $customkey], WCPGSK_DOMAIN ),  
  4066. 'required' => ( ($options['woofields']['required_' . $customkey] == 1) ? true : false),  
  4067. 'options' => $seloptions,  
  4068. 'default' => $selected,  
  4069. 'custom_attributes' => $custom_attributes,  
  4070. 'class' => $clone_class,  
  4071. 'validate' => $validate,  
  4072. 'clear' => $clear  
  4073. ); 
  4074. break; 
  4075. return $field; 
  4076.  
  4077. private function explodeParameters($settings) { 
  4078. $params = array(); 
  4079. foreach (explode('&', $settings) as $chunk) { 
  4080. $param = explode("=", $chunk); 
  4081.  
  4082. if ($param) { 
  4083. $key = str_replace('wcpgsk_add_', '', urldecode($param[0])); 
  4084. if (!empty($key)) 
  4085. $params[$key] = urldecode($param[1]); 
  4086. $new_choices = array(); 
  4087.  
  4088.  
  4089. // explode choices from each line 
  4090. if( isset($params[$key]) && $params[$key] && (strpos($key, 'options') !== false || strpos($key, 'selected') !== false) ) 
  4091. // stripslashes ("") 
  4092. $params[$key] = stripslashes_deep($params[$key]); 
  4093.  
  4094. if(strpos($params[$key], "\n") !== false) 
  4095. // found multiple lines, explode it 
  4096. $params[$key] = explode("\n", $params[$key]); 
  4097. else 
  4098. // no multiple lines!  
  4099. $params[$key] = array($params[$key]); 
  4100.  
  4101. // key => value 
  4102. foreach($params[$key] as $line) 
  4103. if(strpos($line, ' : ') !== false) 
  4104. $option = explode(' : ', $line); 
  4105. $new_choices[ trim($option[0]) ] = trim($option[1]); 
  4106. else 
  4107. $new_choices[ trim($line) ] = trim($line); 
  4108. // update options 
  4109. $params[$key] = $new_choices; 
  4110. return $params; 
  4111.  
  4112. public function explodeAttribute($param) { 
  4113. $params = array(); 
  4114.  
  4115. if ($param) { 
  4116.  
  4117. if(strpos($param, "\n") !== false) 
  4118. // found multiple lines, explode it 
  4119. $params[0] = explode("\n", $param); 
  4120. else 
  4121. // no multiple lines!  
  4122. $params[0] = array($param); 
  4123.  
  4124. // key => value 
  4125. foreach($params[0] as $line) 
  4126. if(strpos($line, ' : ') !== false) 
  4127. $option = explode(' : ', $line); 
  4128. $new_choices[ trim($option[0]) ] = trim($option[1]); 
  4129. else 
  4130. $new_choices[ trim($line) ] = trim($line); 
  4131. // update options 
  4132. $params[0] = $new_choices; 
  4133. return $params; 
  4134.  
  4135. /** 
  4136. * Helper function to calculate difference in days (php < 5.3 compatible)  
  4137. * @access public 
  4138. * @param string $formdate  
  4139. * @since 1.7.1 
  4140. * @return int $days 
  4141. */  
  4142. public function datediffdays($formdate) { 
  4143. $dateSplits = explode("/", $formdate); 
  4144. $date1 = strtotime(date('Y-m-d')); 
  4145. $date2 = mktime(0, 0, 0, (int)$dateSplits[1], (int)$dateSplits[2], (int)$dateSplits[0]); 
  4146. $days = ($date2 - $date1)/(3600*24); 
  4147. // returns numberofdays 
  4148. return $days;  
  4149. }  
  4150.  
  4151. /** 
  4152. * Helper function to validate a date (php < 5.3 compatible)  
  4153. * @access public 
  4154. * @param string $formdate  
  4155. * @since 1.7.1 
  4156. * @return int $days 
  4157. */  
  4158. function ValidateDate($formdate, $format = 'Y-m-d') { 
  4159. $version = explode('.', phpversion()); 
  4160. $dateSplits = explode("/", $formdate); 
  4161. if ( count($dateSplits) == 3 ) : 
  4162. return checkdate($dateSplits[1], $dateSplits[2], $dateSplits[0]); 
  4163. else : 
  4164. return false; 
  4165. endif; 
  4166. }  
  4167. /** 
  4168. * Our admin menu and admin scripts 
  4169. * @access public 
  4170. * @since 1.1.0 
  4171. * @return void 
  4172. */ 
  4173. public function wcpgsk_admin_menu() { 
  4174. // Add a new submenu under Woocommerce: 
  4175. global $wcpgsk_name; 
  4176. $wcpgsk_name = apply_filters('wcpgsk_plus_name', $wcpgsk_name); 
  4177. add_submenu_page( 'woocommerce' , __( $wcpgsk_name, WCPGSK_DOMAIN ), __( $wcpgsk_name, WCPGSK_DOMAIN ), 'manage_options', WCPGSK_DOMAIN, array($this, 'wcpgsk__options_page') ); 
  4178. add_action( 'admin_enqueue_scripts', array($this, 'wcpgsk_admin_scripts') ); 
  4179.  
  4180. /** 
  4181. * Our admin scripts 
  4182. * @access public 
  4183. * @since 1.1.0 
  4184. * @return void 
  4185. */ 
  4186. public function wcpgsk_admin_scripts( $hook_suffix ) { 
  4187. if ( $hook_suffix == 'woocommerce_page_wcpgsk' ) { 
  4188.  
  4189. if( !wp_script_is('jquery-ui-accordion', 'queue') ) { 
  4190. wp_enqueue_script('jquery-ui-accordion'); 
  4191.  
  4192. wp_enqueue_script( 'wcpgsk_admin', plugins_url( '/assets/js/wcpgsk_admin.js', $this->file ), '', '' ); 
  4193.  
  4194. if(!wp_script_is('jquery-ui-sortable', 'queue')) { 
  4195. wp_enqueue_script('jquery-ui-sortable'); 
  4196. if(!wp_script_is('jquery-ui-dialog', 'queue')) { 
  4197. wp_enqueue_script('jquery-ui-dialog'); 
  4198. wp_enqueue_script( 'chosen-order', plugins_url( '/assets/js/chosen.order.jquery.min.js', $this->file ), '', '' ); 
  4199.  
  4200. wp_register_script('accordion-js', plugins_url( '/assets/js/accordion.js', $this->file ), '', '', false); 
  4201. wp_register_style('accordion-styles', plugins_url( '/assets/css/accordion_styles.css', $this->file ), '', ''); 
  4202. wp_register_style('wcpgsk-styles', plugins_url( '/assets/css/wcpgsk_styles.css', $this->file ), '', ''); 
  4203.  
  4204. wp_enqueue_script( 'accordion-js' ); 
  4205. wp_enqueue_style( 'accordion-styles' ); 
  4206. wp_enqueue_style( 'wcpgsk-styles' ); 
  4207. // Include in admin_enqueue_scripts action hook 
  4208. wp_enqueue_media(); 
  4209. wp_enqueue_script( 'custom-header' );  
  4210.  
  4211.  
  4212.  
  4213.  
  4214. /** 
  4215. * Run on activation. 
  4216. * @access public 
  4217. * @since 1.1.0 
  4218. * @return void 
  4219. */ 
  4220. public function activation() { 
  4221. $this->register_plugin_version(); 
  4222. global $wcpgsk_options; 
  4223. $this->wcpgsk_initial_settings();  
  4224. } // End activation() 
  4225.  
  4226. /** 
  4227. * Register the plugin's version. 
  4228. * @access public 
  4229. * @since 1.1.0 
  4230. * @return void 
  4231. */ 
  4232. private function register_plugin_version () { 
  4233. if ( $this->version != '' ) { 
  4234. update_option( WCPGSK_DOMAIN . '-version', $this->version ); 
  4235. } // End register_plugin_version() 
  4236.  
  4237. // Plugin links 
  4238. public function wcpgsk_admin_plugin_actions($links) { 
  4239. $wcpgsk_links = array( 
  4240. '<a href="admin.php?page=' . WCPGSK_DOMAIN . '">'.__('Settings').'</a>',  
  4241. ); 
  4242. return array_merge( $wcpgsk_links, $links ); 
  4243.  
  4244. /** 
  4245. * Initial settings for our plugin 
  4246. * @access public 
  4247. * @since 1.1.0 
  4248. * @changed 1.6.2 add wcpgsk default settings for billing and shipping fields 
  4249. * @return void 
  4250. */  
  4251. private function wcpgsk_initial_settings() { 
  4252. global $woocommerce; 
  4253. $options = get_option('wcpgsk_settings'); 
  4254.  
  4255. if ( !$options ) : 
  4256.  
  4257. $defaults = array(  
  4258. 'filters' => array( 
  4259. 'loop_shop_per_page' => get_option( 'posts_per_page' ),  
  4260. 'loop_shop_columns' => '4',  
  4261. 'woocommerce_product_thumbnails_columns' => '3',  
  4262. 'woocommerce_product_description_tab_title' => __('Description', 'woocommerce'),  
  4263. 'woocommerce_product_description_heading' => __( 'Product Description', 'woocommerce' ),  
  4264. 'woocommerce_product_additional_information_tab_title' => __('Additional Information', 'woocommerce'),  
  4265. 'woocommerce_product_additional_information_heading' => __( 'Additional Information', 'woocommerce' ),  
  4266.  
  4267. 'woocommerce_checkout_must_be_logged_in_message' => __( 'You must be logged in to checkout.', 'woocommerce' ),  
  4268.  
  4269. 'woocommerce_checkout_login_message' => __( 'Returning customer?', 'woocommerce' ),  
  4270.  
  4271. 'woocommerce_checkout_coupon_message' => __( 'Have a coupon?', 'woocommerce' ),  
  4272. 'woocommerce_checkout_coupon_link_message' => __( 'Click here to enter your code', 'woocommerce' ),  
  4273.  
  4274. 'woocommerce_order_button_text' => __( 'Place order', 'woocommerce' ),  
  4275. 'woocommerce_pay_order_button_text' => __( 'Pay for order', 'woocommerce' ),  
  4276. 'woocommerce_thankyou_order_received_text' => __( 'Thank you. Your order has been received.', 'woocommerce' ),  
  4277. 'woocommerce_countries_tax_or_vat' => $this->WC()->countries->tax_or_vat(),  
  4278. 'woocommerce_countries_inc_tax_or_vat' => $this->WC()->countries->inc_tax_or_vat(),  
  4279. 'woocommerce_countries_ex_tax_or_vat' => $this->WC()->countries->ex_tax_or_vat(),  
  4280. ),  
  4281. 'wcpgsk_forms' => array( array( 
  4282. 'label' => __( 'Label', WCPGSK_DOMAIN ),  
  4283. 'placeholder' => __( 'Placeholder', WCPGSK_DOMAIN ))),  
  4284. 'cart' => array( 
  4285. 'addemptycart' => 0,  
  4286. 'minmaxstepproduct' => 0,  
  4287. 'minitemscart' => 1,  
  4288. 'maxitemscart' => 3,  
  4289. 'minqtycart' => 0,  
  4290. 'maxqtycart' => 0,  
  4291. 'minvariationperproduct' => 1,  
  4292. 'maxvariationperproduct' => 1,  
  4293. 'maxqty_variation' => 0,  
  4294. 'minqty_variation' => 0,  
  4295. 'maxqty_variable' => 0,  
  4296. 'minqty_variable' => 0,  
  4297. 'maxqty_grouped' => 0,  
  4298. 'minqty_grouped' => 0,  
  4299. 'maxqty_external' => 0,  
  4300. 'minqty_external' => 0,  
  4301. 'maxqty_simple' => 0,  
  4302. 'minqty_simple' => 0,  
  4303. 'variationscountasproduct' => 0,  
  4304. 'variationproductnoqty' => 0,  
  4305. 'variableproductnoqty' => 0,  
  4306. 'groupedproductnoqty' => 0,  
  4307. 'externalproductnoqty' => 0,  
  4308. 'simpleproductnoqty' => 0),  
  4309. 'checkoutform' => array( 
  4310. 'cartitemforms' => 1,  
  4311. 'servicetitle' => __('Service data', WCPGSK_DOMAIN),  
  4312. 'serviceformmerge' => 'woocommerce_before_order_notes',  
  4313. 'sharedtitle' => __('Additional Information', WCPGSK_DOMAIN),  
  4314. 'sharedformmerge' => 'woocommerce_after_checkout_billing_form',  
  4315. 'tooltippersonalization' => '',  
  4316. 'billingemailvalidator' => 0,  
  4317. 'mindate' => 2,  
  4318. 'maxdate' => 450,  
  4319. 'caltimepicker' => 0,  
  4320. 'enabletooltips' => 1,  
  4321. 'enabletimesliders' => 1,  
  4322. 'cssclass' => ''),  
  4323. 'variations' => array( 
  4324. 'extendattributes' => 1,  
  4325. 'sortextendattributes' => 1),  
  4326. 'process' => array( 
  4327. 'fastcheckoutbtn' => '',  
  4328. 'fastcart' => 0,  
  4329. 'fastcheckout' => 0,  
  4330. 'paymentgateways' => 0,  
  4331. 'onsalelabel' => 'Sale!',  
  4332. 'backorderlabel' => '',  
  4333. 'emptycartlabel' => 'Empty cart?',  
  4334. 'confirmemptycart' => 'Yes, empty cart',  
  4335. 'empty_price_html' => ''),  
  4336. 'email' => array( 
  4337. 'wc_cc_email' => '',  
  4338. 'wc_bcc_email' => ''),  
  4339. ); 
  4340. //add default woocommerce billing and shipping field settings to wcpgsk settings to fix the problem of fields not showing up after activation of our plugin 
  4341. $checkout_fields = array_merge($woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), 'billing_' ), $woocommerce->countries->get_address_fields( $woocommerce->countries->get_base_country(), 'shipping_' )); 
  4342. foreach ($checkout_fields as $key => $field) :  
  4343. $defaults['woofields']['placeholder_' . $key] = isset($checkout_fields[$key]['placeholder']) ? $checkout_fields[$key]['placeholder'] : ''; 
  4344. $defaults['woofields']['label_' . $key] = isset($checkout_fields[$key]['label']) ? $checkout_fields[$key]['label'] : ''; 
  4345. $defaults['woofields']['required_' . $key] = isset($checkout_fields[$key]['required']) ? $checkout_fields[$key]['required'] : 0; 
  4346. $defaults['woofields']['remove_' . $key] = 0; 
  4347. $defaults['woofields']['class_' . $key] = isset($checkout_fields[$key]['class']) ? $checkout_fields[$key]['class'][0] : 'form-row-wide';  
  4348. $defaults['woofields']['settings_' . $key] = ''; 
  4349. endforeach; 
  4350.  
  4351. add_option( 'wcpgsk_settings', apply_filters( 'wcpgsk_defaults', $defaults ) ); 
  4352. endif; 
  4353.  
  4354. /** 
  4355. * Load the plugin's localisation file. 
  4356. * @access public 
  4357. * @since 1.1.0 
  4358. * @return void 
  4359. */ 
  4360. public function load_localisation () { 
  4361. load_plugin_textdomain( WCPGSK_DOMAIN, false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); 
  4362. } // End load_localisation() 
  4363.  
  4364. /** 
  4365. * Load the plugin textdomain from the main WordPress "languages" folder. 
  4366. * @since 1.1.0 
  4367. * @return void 
  4368. */ 
  4369. public function load_plugin_textdomain () { 
  4370. $domain = WCPGSK_DOMAIN; 
  4371. // The "plugin_locale" filter is also used in load_plugin_textdomain() 
  4372. $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); 
  4373.  
  4374. load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); 
  4375. load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); 
  4376. } // End load_plugin_textdomain() 
  4377.  
  4378. public function phpdie() { 
  4379. if (defined('PHPUNIT_TESTING')) { 
  4380. //do nothing 
  4381. //throw new TestingPhpDieException(); 
  4382. } else { 
  4383. die(); 
  4384. }  
  4385.  
  4386. /** 
  4387. * Optimize load by dequeue if not necessary. 
  4388. * @since 1.9.0 
  4389. * @changed 1.9.8 
  4390. * @return void 
  4391. */ 
  4392. public function wcpgsk_handle_scripts() { 
  4393.  
  4394. }  
  4395.  
  4396. /** 
  4397. * Returns the WooCommerce instance 
  4398. * @since 1.9.2 
  4399. * @return WooCommerce woocommerce instance 
  4400. */ 
  4401. private function WC() { 
  4402.  
  4403. if ( function_exists( 'WC' ) && !is_null( WC() ) ) : 
  4404. return WC(); 
  4405. else : 
  4406. global $woocommerce; 
  4407. return $woocommerce; 
  4408. endif; 
  4409.  
  4410. /** 
  4411. * Try to get rid of generator if not a WooCommerce page 
  4412. * @since 1.9.0 
  4413. * @return void 
  4414. */  
  4415. public function wcpgsk_degenerate() {  
  4416. global $wp_scripts;  
  4417. //first check that woo exists to prevent fatal errors 
  4418. if ( function_exists( 'is_woocommerce' ) ) : 
  4419. $options = get_option( 'wcpgsk_settings' ); 
  4420.  
  4421. //dequeue scripts and styles 
  4422. if ( is_cart() ) : 
  4423. wp_enqueue_script( 'wcpgsk-cart', plugins_url('/assets/js/wcpgsk-cart.js', $this->file) , array('jquery'), '', false); 
  4424. wp_enqueue_style( 'wcpgsk-cart-css', plugins_url('/assets/css/wcpgsk-cart.css', $this->file) , array(), ''); 
  4425. endif; 
  4426. if ( is_checkout() || is_account_page() ) : 
  4427. wp_enqueue_script( 'jquery-ui-dialog' ); 
  4428. wp_enqueue_script( 'jquery-ui-datepicker' ); 
  4429. wp_enqueue_script( 'jquery-ui-slider' ); 
  4430. wp_enqueue_script( 'jquery-ui-button' ); 
  4431.  
  4432. wp_enqueue_script( 'jquery-ui-sliderAccess', plugins_url('/assets/js/jquery-ui-sliderAccess.js', $this->file) , '', '', false); 
  4433. if ( isset( $options['checkoutform']['caltimepicker'] ) && 1 == $options['checkoutform']['caltimepicker'] ) : 
  4434. wp_enqueue_style( 'jquery-ui-timepicker-css', plugins_url('/assets/css/jquery.ui.timepicker.css', $this->file) , array(), ''); 
  4435. wp_enqueue_script( 'jquery-ui-timepicker-addon', plugins_url('/assets/js/jquery.ui.timepicker.js', $this->file) , array('jquery'), '', true);  
  4436. else : 
  4437. wp_enqueue_script( 'jquery-ui-timepicker-addon', plugins_url('/assets/js/jquery-ui-timepicker-addon.js', $this->file) , array('jquery'), '', true); 
  4438. endif; 
  4439.  
  4440. wp_enqueue_script( 'wcpgsk-validate', plugins_url('/assets/js/wcpgsk-validate.js', $this->file) , '', '', false); 
  4441. wp_enqueue_script( 'wcpgsk-userjs', plugins_url('wcpgsk-user.js', $this->file) , '', '', false); 
  4442.  
  4443. $jquery_version = isset( $wp_scripts->registered['jquery-ui-core']->ver ) ? $wp_scripts->registered['jquery-ui-core']->ver : '1.9.2'; 
  4444. wp_enqueue_style( 'jquery-ui-style', apply_filters('wcpgsk_jquery_ui', '//ajax.googleapis.com/ajax/libs/jqueryui/' . $jquery_version . '/themes/smoothness/jquery-ui.css', plugins_url('/assets/css/jquery-ui.css', $this->file) ), array(), ''); 
  4445.  
  4446. wp_enqueue_style( 'jquery-ui-timepicker-addon', plugins_url('/assets/css/jquery-ui-timepicker-addon.css', $this->file) , array(), ''); 
  4447. wp_enqueue_style( 'wcpgsk-country', plugins_url('/assets/css/wcpgsk-checkout.css', $this->file) , array(), ''); 
  4448. endif; 
  4449. endif; 
  4450. }  
  4451. }