@@ -32,7 +32,7 @@ public function __construct()
32
32
if ('on ' === Settings::getOption ('coupons ' , Features::getID (), 'on ' )) {
33
33
add_action ('woocommerce_coupon_loaded ' , array ($ this , 'couponLoaded ' ));
34
34
35
- add_action ('wp_loaded ' , array ($ this , 'registerCouponStringsForTranslation ' ));
35
+ add_action ('wp_loaded ' , array ($ this , 'adminRegisterCouponStrings ' ));
36
36
37
37
//apply label filter with higher priority than woocommerce-auto-added-coupons
38
38
add_filter ('woocommerce_cart_totals_coupon_label ' ,
@@ -82,6 +82,7 @@ public function getFreeProductsInLanguage($productIds, $coupon)
82
82
*/
83
83
public function translateLabel ($ value , $ coupon )
84
84
{
85
+ $ this ->registerCouponStringsForTranslation ();
85
86
return sprintf (esc_html__ ('Coupon: %s ' , 'woocommerce ' ),
86
87
pll__ (\get_post ($ coupon ->get_id ())->post_title ));
87
88
}
@@ -95,6 +96,7 @@ public function translateLabel($value, $coupon)
95
96
*/
96
97
public function translateDescription ($ value , $ coupon )
97
98
{
99
+ $ this ->registerCouponStringsForTranslation ();
98
100
return pll__ ($ value );
99
101
}
100
102
/**
@@ -107,35 +109,46 @@ public function translateDescription($value, $coupon)
107
109
*/
108
110
public function translateMessage ($ value , $ coupon )
109
111
{
112
+ $ this ->registerCouponStringsForTranslation ();
110
113
return pll__ ($ value );
111
114
}
112
115
116
+ public function adminRegisterCouponStrings ()
117
+ {
118
+ if (is_admin () && (!is_ajax ())){
119
+ $ this ->registerCouponStringsForTranslation ();
120
+ }
121
+ }
113
122
/**
114
123
* Register coupon titles adn descriptions in Polylang's Strings translations table.
115
124
*/
116
125
public function registerCouponStringsForTranslation ()
117
126
{
118
- if (function_exists ('pll_register_string ' )) {
119
- $ coupons = $ this ->getCoupons ();
127
+ static $ coupons_loaded ;
128
+ if (! $ coupons_loaded ){
129
+ if (function_exists ('pll_register_string ' )) {
130
+ $ coupons = $ this ->getCoupons ();
120
131
121
- foreach ($ coupons as $ coupon ) {
122
- //$code = wc_format_coupon_code($coupon->post_title);
123
- pll_register_string ($ coupon ->post_name , $ coupon ->post_title ,
124
- __ ('Woocommerce Coupon Names ' , 'woo-poly-integration ' ));
125
- pll_register_string ($ coupon ->post_name . '_description ' , $ coupon ->post_excerpt ,
126
- __ ('Woocommerce Coupon Names ' , 'woo-poly-integration ' ), true );
132
+ foreach ($ coupons as $ coupon ) {
133
+ //$code = wc_format_coupon_code($coupon->post_title);
134
+ pll_register_string ($ coupon ->post_name , $ coupon ->post_title ,
135
+ __ ('Woocommerce Coupon Names ' , 'woo-poly-integration ' ));
136
+ pll_register_string ($ coupon ->post_name . '_description ' , $ coupon ->post_excerpt ,
137
+ __ ('Woocommerce Coupon Names ' , 'woo-poly-integration ' ), true );
127
138
128
- $ coupon_message = get_post_meta ($ coupon ->ID , '_wjecf_enqueue_message ' , true );
129
- if ($ coupon_message ) {
130
- pll_register_string ($ coupon ->post_name . '_message ' , $ coupon_message ,
131
- __ ('Woocommerce Coupon Names ' , 'woo-poly-integration ' ), true );
132
- }
133
- $ freeproduct_message = get_post_meta ($ coupon ->ID , '_wjecf_select_free_product_message ' , true );
134
- if ($ freeproduct_message ) {
135
- pll_register_string ($ coupon ->post_name . '_freeproductmessage ' , $ coupon_message ,
136
- __ ('Woocommerce Coupon Names ' , 'woo-poly-integration ' ), true );
139
+ $ coupon_message = get_post_meta ($ coupon ->ID , '_wjecf_enqueue_message ' , true );
140
+ if ($ coupon_message ) {
141
+ pll_register_string ($ coupon ->post_name . '_message ' , $ coupon_message ,
142
+ __ ('Woocommerce Coupon Names ' , 'woo-poly-integration ' ), true );
143
+ }
144
+ $ freeproduct_message = get_post_meta ($ coupon ->ID , '_wjecf_select_free_product_message ' , true );
145
+ if ($ freeproduct_message ) {
146
+ pll_register_string ($ coupon ->post_name . '_freeproductmessage ' , $ coupon_message ,
147
+ __ ('Woocommerce Coupon Names ' , 'woo-poly-integration ' ), true );
148
+ }
137
149
}
138
150
}
151
+ $ coupons_loaded = true ;
139
152
}
140
153
}
141
154
0 commit comments