John Davidson

php - Change text in givewp WordPress plugin

0 comments
Message:


I am using the following code snippet to change the text in a WordPress donation form using the plugin GiveWP. The code is adapted from here. It is important that this code snippet only changes the text on one donation form (with id 590 in this case).


add_action( 'give_pre_form_output', function( $form_id ) {
if ( $form_id == 590 ) {
add_filter( 'gettext', function( $translations, $text, $domain) {
if ( $domain == 'give' && $text == 'Secure Donation' ) {
return __( 'Secure Payment', 'give' );
}
return $translations;
}, 10, 3);
}
});

The code works as expected, except for the receipt section of the form (i.e. after the user has submitted the payment), where the text remains unchanged. If I remove the wrapping function that checks for $form_id the text is changed everywhere, but this would affect other donation forms that I don't want to change.


Is there a way to change the text on the payment receipt section of the form on a per-form basis?



My Answer:
) {
if ( $text === 'Donate Now' ) {
return 'Support Us';
}
}
return $translations;
}, 10, 3 );
}
});

This code snippet will change the text "Donate Now" to "Support Us" on the donation form with id 590 in GiveWP plugin. You can modify the text and form id as needed for your specific use case.

Rate this post

3 of 5 based on 3870 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us