WCML_WC_Memberships

The WooCommerce Multilingual WCML WC Memberships class.

Defined (1)

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

/compatibility/class-wcml-wc-memberships.php  
  1. class WCML_WC_Memberships{ 
  2.  
  3. public function add_hooks() { 
  4.  
  5. add_filter( 'parse_request', array( $this, 'adjust_query_vars' ) ); 
  6. add_filter( 'wcml_register_endpoints_query_vars', array( $this, 'register_endpoints_query_vars' ), 10, 3 ); 
  7. add_filter( 'wcml_endpoint_permalink_filter', array( $this, 'endpoint_permalink_filter' ), 10, 2 ); 
  8. add_filter( 'wc_memberships_members_area_my-memberships_actions', array( $this, 'filter_actions_links' ) ); 
  9.  
  10. add_action( 'wp_enqueue_scripts', array( $this, 'load_assets' ) ); 
  11.  
  12. public function register_endpoints_query_vars( $query_vars, $wc_vars, $object ) { 
  13. $query_vars[ 'members_area' ] = $this->get_translated_endpoint( $object ); 
  14.  
  15. return $query_vars; 
  16.  
  17. public function get_translated_endpoint( $object ) { 
  18.  
  19. $translation = $object->get_endpoint_translation( 
  20. 'members_area',  
  21. get_option( 'woocommerce_myaccount_members_area_endpoint', 'members-area' ) 
  22. ); 
  23.  
  24. return $translation; 
  25.  
  26. public function adjust_query_vars( $q ) { 
  27.  
  28. if( !isset( $q->query_vars['members-area'] ) && isset( $q->query_vars[ 'members_area' ] ) ) { 
  29. $q->query_vars['members-area'] = $q->query_vars[ 'members_area' ]; 
  30.  
  31. return $q; 
  32.  
  33. public function endpoint_permalink_filter( $endpoint, $key ) { 
  34.  
  35. if( 'members_area' === $key ) { 
  36. $endpoint = get_option( 'woocommerce_myaccount_members_area_endpoint', 'members-area' ); 
  37.  
  38. return $endpoint; 
  39.  
  40. public function filter_actions_links( $actions ) { 
  41.  
  42. foreach ( $actions as $key => $action ) { 
  43. if( 'view' === $key ) { 
  44. $membership_endpoints = $this->get_membership_endpoints(); 
  45. $actions[ $key ][ 'url' ] = str_replace( $membership_endpoints[ 'original' ], $membership_endpoints[ 'translated' ], $action[ 'url' ] ); 
  46.  
  47. return $actions; 
  48.  
  49. public function load_assets( ) { 
  50. global $post; 
  51.  
  52. if( isset( $post->ID ) && wc_get_page_id( 'myaccount' ) == $post->ID ) { 
  53. wp_register_script( 'wcml-members-js', WCML_PLUGIN_URL . '/compatibility/res/js/wcml-members.js', array( 'jquery' ), WCML_VERSION ); 
  54. wp_enqueue_script( 'wcml-members-js' ); 
  55. wp_localize_script( 'wcml-members-js', 'endpoints', $this->get_membership_endpoints() ); 
  56.  
  57.  
  58. public function get_membership_endpoints() { 
  59.  
  60. $endpoint = get_option( 'woocommerce_myaccount_members_area_endpoint', 'members-area' ); 
  61. $translated_endpoint = apply_filters( 'wpml_translate_single_string', $endpoint, 'WooCommerce Endpoints', 'members_area' ); 
  62.  
  63. return array( 
  64. 'original' => $endpoint,  
  65. 'translated' => $translated_endpoint 
  66. ); 
  67.  
  68.