This repository has been archived by the owner on Mar 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements #337 by enabling privacy strings translation
implements #337 by adding woocommerce privacy strings to the Polylang strings translation table
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?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; | ||
|
||
/** | ||
* Privacy. | ||
* | ||
*/ | ||
class Privacy | ||
{ | ||
|
||
/** | ||
* Construct initiated on init by Plugin.php | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->registerPrivacyStrings(); | ||
add_filter('woocommerce_get_privacy_policy_text', array($this, 'translatePrivacyPolicyText'), 10, 2); | ||
} | ||
|
||
/** | ||
* Register woocommerce privacy policy messages in polylang strings | ||
* translations table. | ||
*/ | ||
public function registerPrivacyStrings() | ||
{ | ||
$this->registerString('woocommerce_checkout_privacy_policy_text', get_option('woocommerce_checkout_privacy_policy_text', sprintf(__('Your personal data will be used to process your order, support your experience throughout this website, and for other purposes described in our %s.', 'woocommerce'), '[privacy_policy]'))); | ||
$this->registerString('woocommerce_registration_privacy_policy_text', get_option('woocommerce_registration_privacy_policy_text', sprintf(__('Your personal data will be used to support your experience throughout this website, to manage access to your account, and for other purposes described in our %s.', 'woocommerce'), '[privacy_policy]'))); | ||
} | ||
|
||
|
||
/** | ||
* Register setting and value in polylang strings translations table. | ||
* | ||
* @param string $setting Name of setting/string to translate | ||
* @param string $value Value in base language | ||
*/ | ||
private function registerString($setting, $value) | ||
{ | ||
if (function_exists('pll_register_string')) { | ||
pll_register_string($setting, $value, __('WooCommerce Privacy', 'woo-poly-integration'), true); | ||
} | ||
} | ||
|
||
/** | ||
* Register setting and value in polylang strings translations table. | ||
* | ||
* @param string $text Text to be translated | ||
* @param string $type Name of privacy policy type 'checkout' or ‘registration’ | ||
*/ | ||
public function translatePrivacyPolicyText($text, $type) | ||
{ | ||
if (function_exists('pll_register_string')) { | ||
$trans = pll__($text); | ||
return ($trans) ? $trans : $text; | ||
} | ||
} | ||
} |