WCML_Extra_Product_Options

The WooCommerce Multilingual WCML Extra Product Options class.

Defined (1)

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

/compatibility/class-wcml-extra-product-options.php  
  1. class WCML_Extra_Product_Options{ 
  2.  
  3. function __construct() { 
  4.  
  5. // commented out because of wcml-1218 
  6. // add_filter( 'get_post_metadata', array( $this, 'product_options_filter'), 100, 4 ); 
  7. // add_action( 'updated_post_meta', array( $this, 'register_options_strings' ), 10, 4 ); 
  8.  
  9. add_action( 'tm_before_extra_product_options', array( $this, 'inf_translate_product_page_strings' ) ); 
  10. add_action( 'tm_before_price_rules', array( $this, 'inf_translate_strings' ) ); 
  11.  
  12. // commented out because of wcml-1218 
  13. /** 
  14.   
  15. function register_options_strings( $meta_id, $id, $meta_key, $options ) { 
  16. if( $meta_key != 'tm_meta' ) 
  17. return false; 
  18.   
  19. $this->filter_options( $options, $id, 'register' ); 
  20.   
  21.   
  22. function product_options_filter( $null, $object_id, $meta_key, $single ) { 
  23. static $no_filter = false; 
  24.   
  25. if( empty($no_filter) && $meta_key == 'tm_meta' && !is_admin() ) { 
  26. $no_filter = true; 
  27.   
  28. $options = maybe_unserialize( get_post_meta( $object_id, $meta_key, $single ) ); 
  29.   
  30. $options = $this->filter_options( $options, $object_id, 'translate' ); 
  31.   
  32. $no_filter = false; 
  33.   
  34. return isset( $options ) ? array( $options ) : $null; 
  35.   
  36. function filter_options( $options, $id, $action ) { 
  37.   
  38. if( !isset( $options[ 'tmfbuilder' ] ) ) { 
  39. return $options; 
  40.   
  41. global $sitepress, $woocommerce_wpml; 
  42. $keys_to_translate = array( 'header_title', 'header_subtitle', 'text_after_price', 'placeholder' ); 
  43.   
  44. $id = apply_filters( 'translate_object_id', $id, get_post_type( $id ), true, $woocommerce_wpml->products->get_original_product_language( $id ) ); 
  45.   
  46. foreach( $options[ 'tmfbuilder' ] as $key => $values ) { 
  47. foreach( $keys_to_translate as $key_text ) { 
  48. if ( preg_match('/.*'.$key_text.'$/', $key ) ) { 
  49. foreach( $values as $value_key => $value ) { 
  50. if( $value ) { 
  51. if( $action == 'register') { 
  52. do_action('wpml_register_single_string', 'wc_extra_product_options', $id.'_option_'.$value_key.'_'.$key, $value ); 
  53. }else{ 
  54. $options[ 'tmfbuilder' ][ $key ][ $value_key ] = apply_filters( 'wpml_translate_single_string', $value, 'wc_extra_product_options', $id.'_option_'.$value_key.'_'.$key); 
  55.   
  56.   
  57. //convert prices 
  58. if( $action == 'translate' && preg_match('/.*price$/', $key ) && !preg_match('/.*text_after_price/', $key )) { 
  59. foreach( $values as $value_key => $value ) { 
  60. if( $value ) { 
  61. if( is_array( $value ) ) { 
  62. foreach( $value as $key_price => $price ) { 
  63. $options[ 'tmfbuilder' ][ $key ][ $value_key ][ $key_price ] = apply_filters( 'wcml_raw_price_amount', $price ); 
  64. }else{ 
  65. $options[ 'tmfbuilder' ][ $key ][ $value_key ] = apply_filters( 'wcml_raw_price_amount', $value ); 
  66.   
  67.   
  68. return $options; 
  69.   
  70. */ 
  71.  
  72. function inf_translate_strings() { 
  73. if( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'tm-global-epo' ) 
  74. $this->inf_message( 'Options Form' ); 
  75.  
  76. function inf_translate_product_page_strings() { 
  77. $this->inf_message( 'Product' ); 
  78.  
  79. function inf_message( $text ) { 
  80. $message = '<div><p class="icl_cyan_box">'; 
  81. $message .= sprintf(__('To translate Extra Options strings please save %s and go to the <b><a href="%s">String Translation interface</a></b>', 'woocommerce-multilingual'), $text, admin_url('admin.php?page='.WPML_ST_FOLDER.'/menu/string-translation.php&context=wc_extra_product_options')); 
  82. $message .= '</p></div>'; 
  83.  
  84. echo $message;