File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Gravity Perks // Conditional Pricing // Add Support for Choice-based Rules with WPML Translations
4+ * https://gravitywiz.com/documentation/gravity-forms-conditional-pricing/
5+ *
6+ * Experimental Snippet 🧪
7+ */
8+ add_filter ( 'gpcp_pricing_logic ' , function ( $ pricing_logic , $ form ) {
9+
10+ if ( isset ( $ GLOBALS ['wpml_gfml_tm_api ' ] ) ) {
11+ /**
12+ * GPCP fetches the pricing logic at several points during the page load. We need to translate our pricing
13+ * rules *before* WPML has translated the form. Otherwise, choice-based conditions will not return a
14+ * translation match since the original choice has already been translated. This is relevant to the
15+ * Gravity_Forms_Multilingual::translate_conditional_logic() call below.
16+ */
17+ static $ wpml_pricing_logic ;
18+ if ( isset ( $ wpml_pricing_logic [ $ form ['id ' ] ] ) ) {
19+ return $ wpml_pricing_logic [ $ form ['id ' ] ];
20+ }
21+ foreach ( $ pricing_logic as &$ field_pricing_logic ) {
22+ /**
23+ * WPML's translate_conditional_logic() method only translates the "fields" and "notifications" section
24+ * and it needs the "fields" section to look up fields for conditional logic so... we use "notifications".
25+ */
26+ $ form ['notifications ' ] = $ field_pricing_logic ;
27+ $ form = $ GLOBALS ['wpml_gfml_tm_api ' ]->translate_conditional_logic ( $ form );
28+ $ field_pricing_logic = $ form ['notifications ' ];
29+ }
30+ $ wpml_pricing_logic [ $ form ['id ' ] ] = $ pricing_logic ;
31+ }
32+
33+ return $ pricing_logic ;
34+ }, 10 , 2 );
You can’t perform that action at this time.
0 commit comments