Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #329 from marian-kadanka/fix-319-ajax-endpoint-url…
Browse files Browse the repository at this point in the history
…-again

Fix Ajax endpoint URL again, fixes #319
  • Loading branch information
hyyan committed Apr 30, 2018
2 parents c7eb1f7 + 888df71 commit f9e7209
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Hyyan/WPI/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@ class Ajax
*/
public function __construct()
{
add_filter('pll_home_url_white_list', array( $this, 'pll_home_url_white_list' ));
add_filter('woocommerce_ajax_get_endpoint', array($this, 'filter_woocommerce_ajax_get_endpoint'), 10, 2);
}

/**
* Add WooCommerce class-wc-ajax.php to the Polylang home_url white list
* Filter woocommerce_ajax_get_endpoint URL - replace the path part
* with the correct relative home URL according to the current language
* and append the query string
*
* @param array $white_list Polylang home_url white list
* @param string $url WC AJAX endpoint URL to filter
* @param string $request
*
* @return array filtered white list
* @return string filtered WC AJAX endpoint URL
*/
public function pll_home_url_white_list($white_list)
public function filter_woocommerce_ajax_get_endpoint($url, $request)
{
$white_list[] = array( 'file' => 'class-wc-ajax.php' );
return $white_list;
global $polylang;
return parse_url($polylang->filters_links->links->get_home_url($polylang->curlang), PHP_URL_PATH) . '?' . parse_url($url, PHP_URL_QUERY);
}
}

0 comments on commit f9e7209

Please sign in to comment.