WCML_Custom_Taxonomy_Translation_UI

The WooCommerce Multilingual WCML Custom Taxonomy Translation UI class.

Defined (1)

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

/inc/template-classes/class-wcml-custom-taxonomy-translation-ui.php  
  1. class WCML_Custom_Taxonomy_Translation_UI extends WPML_Templates_Factory { 
  2.  
  3. private $woocommerce_wpml; 
  4. private $sitepress; 
  5.  
  6. private $custom_taxonomies = array(); 
  7. private $product_builtin_taxonomy_names = array( 'product_cat', 'product_tag', 'product_shipping_class', 'product_type' ); //'product_type' is used for tags (?) 
  8.  
  9.  
  10. public function __construct( &$woocommerce_wpml, &$sitepress ) { 
  11. parent::__construct(); 
  12.  
  13. $this->woocommerce_wpml = $woocommerce_wpml; 
  14. $this->sitepress = $sitepress; 
  15.  
  16. $product_attributes = array(); 
  17. $attributes = wc_get_attribute_taxonomies(); 
  18. foreach( $attributes as $attribute ) { 
  19. $product_attributes[ 'pa_' . $attribute->attribute_name ] = $attribute; 
  20.  
  21. $product_taxonomies = get_object_taxonomies( 'product', 'objects' ); 
  22. foreach( $product_taxonomies as $product_taxonomy_name => $product_taxonomy_object ) { 
  23. if( 
  24. !isset( $product_attributes[$product_taxonomy_name] ) && 
  25. !in_array( $product_taxonomy_name, $this->product_builtin_taxonomy_names ) && 
  26. is_taxonomy_translated( $product_taxonomy_name ) 
  27. ) { 
  28. $this->custom_taxonomies[$product_taxonomy_name] = $product_taxonomy_object; 
  29.  
  30.  
  31. public function get_model() { 
  32.  
  33. $taxonomy = isset( $_GET['taxonomy'] ) ? $_GET['taxonomy'] : false; 
  34. $selected_taxonomy = false; 
  35. $translation_ui = ''; 
  36.  
  37. if( $this->custom_taxonomies && !empty( $taxonomy ) ) { 
  38. foreach( $this->custom_taxonomies as $taxonomy_name => $taxonomy_object ) { 
  39. if( $taxonomy_name == $taxonomy ) { 
  40. $selected_taxonomy = $taxonomy_object; 
  41. break; 
  42.  
  43. if( $selected_taxonomy ) { 
  44. $WPML_Translate_Taxonomy = 
  45. new WPML_Taxonomy_Translation( 
  46. isset( $selected_taxonomy->name ) ? $selected_taxonomy->name: '',  
  47. array( 
  48. 'taxonomy_selector'=> false 
  49. ); 
  50. }elseif( $this->custom_taxonomies ) { 
  51. $empty_value = new stdClass(); 
  52. $empty_value->name = ''; 
  53. $empty_value->label = __( '--Taxonomy--', 'woocommerce-multilingual' ); 
  54. array_unshift( $this->custom_taxonomies, $empty_value ); 
  55.  
  56. $WPML_Translate_Taxonomy = 
  57. new WPML_Taxonomy_Translation( 
  58. '',  
  59. array( 
  60. 'taxonomy_selector' => false 
  61. ),  
  62. new WPML_UI_Screen_Options_Factory( $this->sitepress ) 
  63. ); 
  64.  
  65. if( isset( $WPML_Translate_Taxonomy ) ) { 
  66. ob_start(); 
  67. $WPML_Translate_Taxonomy->render(); 
  68. $translation_ui = ob_get_contents(); 
  69. ob_end_clean(); 
  70.  
  71. $model = array( 
  72.  
  73. 'taxonomies' => $this->custom_taxonomies,  
  74. 'selected_taxonomy' => $selected_taxonomy,  
  75. 'strings' => array( 
  76. 'no_taxonomies' => __( 'There are no translatable product custom taxonomies defined', 'woocommerce-multilingual' ),  
  77. 'select_label' => __('Select the taxonomy to translate: ', 'woocommerce-multilingual'),  
  78. 'loading' => __( 'Loading ...', 'woocommerce-multilingual' ) 
  79. ),  
  80. 'translation_ui' => $translation_ui 
  81.  
  82. ); 
  83.  
  84. return $model; 
  85.  
  86.  
  87.  
  88. public function init_template_base_dir() { 
  89. $this->template_paths = array( 
  90. WCML_PLUGIN_PATH . '/templates/',  
  91. ); 
  92.  
  93. public function get_template() { 
  94. return 'custom-taxonomy-translation.twig';