Skip to content

Commit 9dbefb2

Browse files
committed
gpi-enable-wpml-for-custom-messages.php: Added snippet to use WPML String Translate for custom messages.
1 parent 4eac0cd commit 9dbefb2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Limit Submissions // Enable `WPML String Translate` for Custom Insufficient,
4+
* Exhausted and Available Inventory Messages.
5+
* https://gravitywiz.com/documentation/gravity-forms-inventory/
6+
*/
7+
add_action( 'init', function() {
8+
if ( function_exists( 'icl_register_string' ) && function_exists( 'gp_inventory' ) ) {
9+
// Update `26` to your form ID
10+
$form_id = '26';
11+
$form = GFAPI::get_form( $form_id );
12+
foreach ( $form['fields'] as $field ) {
13+
if ( rgar( $field, 'gpiMessageInventoryInsufficient', false ) ) {
14+
icl_register_string( 'gp-inventory', "inventory-insufficient-message-{$form_id}-{$field->id}", $field['gpiMessageInventoryInsufficient'] );
15+
}
16+
if ( rgar( $field, 'gpiMessageInventoryExhausted', false ) ) {
17+
icl_register_string( 'gp-inventory', "inventory-exhausted-message-{$form_id}-{$field->id}", $field['gpiMessageInventoryExhausted'] );
18+
}
19+
if ( rgar( $field, 'gpiMessageInventoryAvailable', false ) ) {
20+
icl_register_string( 'gp-inventory', "inventory-available-message-{$form_id}-{$field->id}", $field['gpiMessageInventoryAvailable'] );
21+
}
22+
}
23+
}
24+
} );

0 commit comments

Comments
 (0)