WJECF_WPML

Class to make WJECF compatible with WPML.

Defined (1)

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

/includes/wjecf-wpml.php  
  1. class WJECF_WPML extends Abstract_WJECF_Plugin { 
  2.  
  3. public function __construct() { 
  4. $this->set_plugin_data( array( 
  5. 'description' => __( 'Compatiblity with WPML.', 'woocommerce-jos-autocoupon' ),  
  6. 'dependencies' => array(),  
  7. 'can_be_disabled' => true 
  8. ) );  
  9.  
  10. public function init_hook() { 
  11. global $sitepress; 
  12. if ( isset( $sitepress ) ) { 
  13. //WJECF_Controller hooks 
  14. add_filter( 'wjecf_get_product_ids', array( $this, 'filter_get_product_ids' ), 10 ); 
  15. add_filter( 'wjecf_get_product_cat_ids', array( $this, 'filter_get_product_cat_ids' ), 10 ); 
  16.  
  17. //HOOKS 
  18.  
  19. public function filter_get_product_ids( $product_ids ) { 
  20. return $this->get_translated_object_ids( $product_ids, 'product' ); 
  21.  
  22. public function filter_get_product_cat_ids( $product_cat_ids ) { 
  23. return $this->get_translated_object_ids( $product_cat_ids, 'product_cat' ); 
  24.  
  25.  
  26. //FUNCTIONS 
  27.  
  28. /** 
  29. * Get the ids of all the translations. Otherwise return the original array 
  30. *  
  31. * @param int|array $product_ids The product_ids to find the translations for 
  32. * @return array The product ids of all translations 
  33. *  
  34. */ 
  35. public function get_translated_object_ids( $object_ids, $object_type ) { 
  36. //Make sure it's an array 
  37. if ( ! is_array( $object_ids ) ) { 
  38. $object_ids = array( $object_ids ); 
  39.  
  40. $translated_object_ids = array(); 
  41. foreach( $object_ids as $object_id) { 
  42. $translated_object_ids[] = apply_filters( 'wpml_object_id', $object_id, $object_type ); 
  43. return $translated_object_ids;