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

Commit 888df71

Browse files
Fix Ajax endpoint URL again, fixes #319
Another change in WC_AJAX->get_endpoint() implementation - see woocommerce/woocommerce#19139 - this time it returns relative URLs. This breaks Polylangs home_url() filter, which can't handle them. We have to use woocommerce_ajax_get_endpoint filter to alter the AJAX endpoint URL according to the current language - replace the path part of the URL with the correct relative home URL and append the query string.
1 parent c7eb1f7 commit 888df71

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Hyyan/WPI/Ajax.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,22 @@ class Ajax
2525
*/
2626
public function __construct()
2727
{
28-
add_filter('pll_home_url_white_list', array( $this, 'pll_home_url_white_list' ));
28+
add_filter('woocommerce_ajax_get_endpoint', array($this, 'filter_woocommerce_ajax_get_endpoint'), 10, 2);
2929
}
3030

3131
/**
32-
* Add WooCommerce class-wc-ajax.php to the Polylang home_url white list
32+
* Filter woocommerce_ajax_get_endpoint URL - replace the path part
33+
* with the correct relative home URL according to the current language
34+
* and append the query string
3335
*
34-
* @param array $white_list Polylang home_url white list
36+
* @param string $url WC AJAX endpoint URL to filter
37+
* @param string $request
3538
*
36-
* @return array filtered white list
39+
* @return string filtered WC AJAX endpoint URL
3740
*/
38-
public function pll_home_url_white_list($white_list)
41+
public function filter_woocommerce_ajax_get_endpoint($url, $request)
3942
{
40-
$white_list[] = array( 'file' => 'class-wc-ajax.php' );
41-
return $white_list;
43+
global $polylang;
44+
return parse_url($polylang->filters_links->links->get_home_url($polylang->curlang), PHP_URL_PATH) . '?' . parse_url($url, PHP_URL_QUERY);
4245
}
4346
}

0 commit comments

Comments
 (0)