Your cart is currently empty!
Place a Gutenberg JetPack contact form anywhere
Adds the Gutenberg JetPack contact form to the My Account Dashboard screen, or wherever else you wish to hook it.
add_action( 'woocommerce_account_dashboard', function() {
// Settings
$to_email = '[email protected]';
$button_color = '#333333';
$button_text = '#ffffff';
$button_label = 'Send';
$email_subject = 'Subject Line';
// Form Code
$current_user = wp_get_current_user();
$from_email = isset( $current_user->user_email )
? $current_user->user_email : '';
$args = implode( ',', [
'"customBackgroundButtonColor":"' . $button_color . '"',
'"customTextButtonColor":"' . $button_text . '"',
'"submitButtonClasses":"wp-block-button__link has-text-color has-background"',
'"hasFormSettingsSet":"yes"',
] );
$blocks = sprintf(
'
<!-- wp:jetpack/contact-form {"subject":"%s","to":"%s","submitButtonText":"%s"%s} -->
<!-- wp:jetpack/field-email {"required":true,"defaultValue":"%s"} /--><br>
<!-- wp:jetpack/field-textarea {"required":true} /--><br>
<!-- /wp:jetpack/contact-form -->
', $email_subject, $to_email, $button_label, $args, $from_email
);
// Render Block
echo apply_filters( 'the_content', $blocks );
} );
Instructions for Place a Gutenberg JetPack contact form anywhere
- Log into a staging or locally hosted clone of your site.
- Install and activate Code Snippets plugin.
- WP Admin > Snippets > Add New
- Copy and paste the code from the section above.
- Check to ensure formatting came over properly.
- Customize the code as desired.
- Add a meaningful title.
- Select whether to run on front-end or back-end (or both).
- Click “Save and Activate”.
- Test your site to ensure it works.
- Disable if any problems, or recover.
- Repeat for live environment.
Need help modifying Place a Gutenberg JetPack contact form anywhere?
Contact me. I can help with fitting projects or refer to my partner.
License
All code snippets are licensed GPLv2 (or later) matching WordPress licensing.
Except when otherwise stated in writing the copyright holders and/or other parties provide the program as-is without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose.
Disclaimer of warranty