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

Commit

Permalink
Fix Ajax endpoint URL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marian-kadanka committed Oct 30, 2017
1 parent c18a273 commit 9f9b758
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Hyyan/WPI/Ajax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* This file is part of the hyyan/woo-poly-integration plugin.
* (c) Hyyan Abo Fakher <hyyanaf@gmail.com>.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Hyyan\WPI;

/**
* Ajax.
*
* Handle Ajax
*
* @author Marian Kadanka <marian.kadanka@gmail.com>
*/
class Ajax {

/**
* Construct object.
*/
public function __construct() {
add_filter( 'pll_home_url_white_list', array( $this, 'pll_home_url_white_list' ) );
}

/**
* Add WooCommerce class-wc-ajax.php to the Polylang home_url white list
*
* @param array $white_list Polylang home_url white list
*
* @return array filtered white list
*/
public function pll_home_url_white_list( $white_list ) {
$white_list[] = array( 'file' => 'class-wc-ajax.php' );
return $white_list;
}

}
1 change: 1 addition & 0 deletions src/Hyyan/WPI/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ protected function registerCore()
new Breadcrumb();
new Tax();
new LocaleNumbers();
new Ajax();
}

/**
Expand Down

0 comments on commit 9f9b758

Please sign in to comment.