WCML_Checkout_Field_Editor

The WooCommerce Multilingual WCML Checkout Field Editor class.

Defined (1)

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

/compatibility/class-wcml-checkout-field-editor.php  
  1. class WCML_Checkout_Field_Editor { 
  2.  
  3. protected $package, $billing, $shipping, $additional; 
  4.  
  5. function __construct() { 
  6. $this->package = (object) array( 
  7. 'kind' => 'WooCommerce Add-On',  
  8. 'kind_slug' => 'woocommerce-add-on',  
  9. 'name' => 'checkout-field-editor',  
  10. 'title' => 'WooCommerce Checkout Field Editor' 
  11. ); 
  12. global $supress_field_modification; 
  13. if ( !is_admin() && !$supress_field_modification ) { 
  14. add_filter( 'pre_option_wc_fields_billing', array($this, 'get_billing') ); 
  15. add_filter( 'pre_option_wc_fields_shipping', array($this, 'get_shipping') ); 
  16. add_filter( 'pre_option_wc_fields_additional', array($this, 'get_additional') ); 
  17. add_filter( 'pre_update_option_wc_fields_billing', array($this, 'register_fields') ); 
  18. add_filter( 'pre_update_option_wc_fields_shipping', array($this, 'register_fields') ); 
  19. add_filter( 'pre_update_option_wc_fields_additional', array($this, 'register_fields') ); 
  20.  
  21. public function register_fields( $fields ) { 
  22. foreach ( $fields as $string_name => $field ) { 
  23. // Translate label 
  24. if ( !empty( $field['label'] ) ) { 
  25. do_action( 'wpml_register_string',  
  26. $field['label'],  
  27. "{$string_name}_label",  
  28. $this->package,  
  29. "{$string_name} Label",  
  30. $this->package->kind 
  31. ); 
  32. // Translate placeholder 
  33. if ( !empty( $field['placeholder'] ) ) { 
  34. do_action( 'wpml_register_string',  
  35. $field['placeholder'],  
  36. "{$string_name}_placeholder",  
  37. $this->package,  
  38. "{$string_name} Placeholder",  
  39. $this->package->kind 
  40. ); 
  41. // Translate options 
  42. if ( !empty( $field['options'] ) ) { 
  43. $i = 1; 
  44. foreach ( $field['options'] as $option ) { 
  45. do_action( 'wpml_register_string',  
  46. $option,  
  47. "{$string_name}_option_{$i}",  
  48. $this->package,  
  49. "{$string_name} Option {$i}",  
  50. $this->package->kind 
  51. ); 
  52. $i++; 
  53. return $fields; 
  54.  
  55. public function translate_fields( $fields ) { 
  56. foreach ( $fields as $string_name => &$field ) { 
  57. // Translate label 
  58. if ( !empty( $field['label'] ) ) { 
  59. $field['label'] = apply_filters( 'wpml_translate_string',  
  60. $field['label'],  
  61. "{$string_name}_label",  
  62. $this->package 
  63. ); 
  64. // Translate placeholder 
  65. if ( !empty( $field['placeholder'] ) ) { 
  66. $field['placeholder'] = apply_filters( 'wpml_translate_string',  
  67. $field['label'],  
  68. "{$string_name}_placeholder",  
  69. $this->package 
  70. ); 
  71. // Translate options 
  72. if ( !empty( $field['options'] ) ) { 
  73. $i = 1; 
  74. foreach ( $field['options'] as $k => $option ) { 
  75. $field['options'][$k] = apply_filters( 'wpml_translate_string',  
  76. $option,  
  77. "{$string_name}_option_{$i}",  
  78. $this->package 
  79. ); 
  80. $i++; 
  81. return $fields; 
  82.  
  83. public function get_billing() { 
  84. if ( is_null( $this->billing ) ) { 
  85. remove_filter( 'pre_option_wc_fields_billing', array($this, 'get_billing') ); 
  86. $this->billing = $this->translate_fields( get_option( 'wc_fields_billing', array() ) ); 
  87. add_filter( 'pre_option_wc_fields_billing', array($this, 'get_billing') ); 
  88. return $this->billing; 
  89.  
  90. public function get_shipping() { 
  91. if ( is_null( $this->shipping ) ) { 
  92. remove_filter( 'pre_option_wc_fields_shipping', array($this, 'get_shipping') ); 
  93. $this->shipping = $this->translate_fields( get_option( 'wc_fields_shipping', array() ) ); 
  94. add_filter( 'pre_option_wc_fields_shipping', array($this, 'get_shipping') ); 
  95. return $this->shipping; 
  96.  
  97. public function get_additional() { 
  98. if ( is_null( $this->additional ) ) { 
  99. remove_filter( 'pre_option_wc_fields_additional', array($this, 'get_additional') ); 
  100. $this->additional = $this->translate_fields( get_option( 'wc_fields_additional', array() ) ); 
  101. add_filter( 'pre_option_wc_fields_additional', array($this, 'get_additional') ); 
  102. return $this->additional;