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

Commit 9f9b758

Browse files
Fix Ajax endpoint URL
WooCommerce 3.2.0 introduced different handling of Ajax endpoint URLs, including call to home_url() function, for more info see woocommerce/woocommerce#16991 This breaks Polylang language detection if language is set from the directory name in pretty permalinks. To address this issue we need to add WooCommerce class-wc-ajax.php file to the white list of the Polylang home_url filter, enabling home_url() function to return correct URL according to the language set.
1 parent c18a273 commit 9f9b758

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Hyyan/WPI/Ajax.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the hyyan/woo-poly-integration plugin.
5+
* (c) Hyyan Abo Fakher <[email protected]>.
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Hyyan\WPI;
12+
13+
/**
14+
* Ajax.
15+
*
16+
* Handle Ajax
17+
*
18+
* @author Marian Kadanka <[email protected]>
19+
*/
20+
class Ajax {
21+
22+
/**
23+
* Construct object.
24+
*/
25+
public function __construct() {
26+
add_filter( 'pll_home_url_white_list', array( $this, 'pll_home_url_white_list' ) );
27+
}
28+
29+
/**
30+
* Add WooCommerce class-wc-ajax.php to the Polylang home_url white list
31+
*
32+
* @param array $white_list Polylang home_url white list
33+
*
34+
* @return array filtered white list
35+
*/
36+
public function pll_home_url_white_list( $white_list ) {
37+
$white_list[] = array( 'file' => 'class-wc-ajax.php' );
38+
return $white_list;
39+
}
40+
41+
}

src/Hyyan/WPI/Plugin.php

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ protected function registerCore()
191191
new Breadcrumb();
192192
new Tax();
193193
new LocaleNumbers();
194+
new Ajax();
194195
}
195196

196197
/**

0 commit comments

Comments
 (0)