|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of the hyyan/woo-poly-integration plugin. |
| 4 | + * (c) Hyyan Abo Fakher <[email protected]>. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | +namespace Hyyan\WPI; |
| 10 | + |
| 11 | +/** |
| 12 | + * Privacy. |
| 13 | + * |
| 14 | + */ |
| 15 | +class Privacy |
| 16 | +{ |
| 17 | + |
| 18 | + /** |
| 19 | + * Construct initiated on init by Plugin.php |
| 20 | + */ |
| 21 | + public function __construct() |
| 22 | + { |
| 23 | + $this->registerPrivacyStrings(); |
| 24 | + add_filter('woocommerce_get_privacy_policy_text', array($this, 'translatePrivacyPolicyText'), 10, 2); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Register woocommerce privacy policy messages in polylang strings |
| 29 | + * translations table. |
| 30 | + */ |
| 31 | + public function registerPrivacyStrings() |
| 32 | + { |
| 33 | + $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]'))); |
| 34 | + $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]'))); |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | + /** |
| 39 | + * Register setting and value in polylang strings translations table. |
| 40 | + * |
| 41 | + * @param string $setting Name of setting/string to translate |
| 42 | + * @param string $value Value in base language |
| 43 | + */ |
| 44 | + private function registerString($setting, $value) |
| 45 | + { |
| 46 | + if (function_exists('pll_register_string')) { |
| 47 | + pll_register_string($setting, $value, __('WooCommerce Privacy', 'woo-poly-integration'), true); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Register setting and value in polylang strings translations table. |
| 53 | + * |
| 54 | + * @param string $text Text to be translated |
| 55 | + * @param string $type Name of privacy policy type 'checkout' or ‘registration’ |
| 56 | + */ |
| 57 | + public function translatePrivacyPolicyText($text, $type) |
| 58 | + { |
| 59 | + if (function_exists('pll_register_string')) { |
| 60 | + $trans = pll__($text); |
| 61 | + return ($trans) ? $trans : $text; |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments