Jetpack

Move Gutenberg JetPack contact

Last updated 2 years ago

PHP
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"',
    ] );
    $content = 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 do_blocks( $content );
 
} );

Tags: #Jetpack

All code snippets are licensed GPLv2 or later unless otherwise stated.