{
  "$schema": "https://playground.wordpress.net/blueprint-schema.json",
  "meta": {
    "title": "Registration Form for WooCommerce demo",
    "description": "WooCommerce store with a custom registration form: name fields, confirm email, billing company and phone, a dropdown, a newsletter checkbox and GDPR consent, also replacing the My Account registration form.",
    "author": "ThemeGrill",
    "categories": [
      "WooCommerce"
    ]
  },
  "landingPage": "/create-account/",
  "preferredVersions": {
    "php": "8.3",
    "wp": "latest"
  },
  "features": {
    "networking": true
  },
  "steps": [
    {
      "step": "setSiteOptions",
      "options": {
        "blogname": "Demo Store",
        "permalink_structure": "/%postname%/"
      }
    },
    {
      "step": "installTheme",
      "themeData": {
        "resource": "wordpress.org/themes",
        "slug": "zakra"
      },
      "options": {
        "activate": true
      }
    },
    {
      "step": "installPlugin",
      "pluginData": {
        "resource": "wordpress.org/plugins",
        "slug": "woocommerce"
      },
      "options": {
        "activate": true
      }
    },
    {
      "step": "installPlugin",
      "pluginData": {
        "resource": "wordpress.org/plugins",
        "slug": "registration-form-for-woocommerce"
      },
      "options": {
        "activate": true
      }
    },
    {
      "step": "runPHP",
      "code": "<?php\nrequire_once '/wordpress/wp-load.php';\nwp_set_current_user( 1 );\n\n// WooCommerce: skip onboarding, open the store, create the shop/account pages.\nupdate_option( 'woocommerce_onboarding_profile', array( 'skipped' => true, 'completed' => true ) );\ndelete_transient( '_wc_activation_redirect' );\nupdate_option( 'woocommerce_admin_install_timestamp', time() - DAY_IN_SECONDS );\nupdate_option( 'woocommerce_task_list_hidden', 'yes' );\nupdate_option( 'woocommerce_coming_soon', 'no' );\nupdate_option( 'woocommerce_store_pages_only', 'no' );\nupdate_option( 'woocommerce_currency', 'USD' );\nupdate_option( 'woocommerce_default_country', 'US:CA' );\n// Let visitors create an account on the My Account page.\nupdate_option( 'woocommerce_enable_myaccount_registration', 'yes' );\nupdate_option( 'woocommerce_registration_generate_username', 'yes' );\nupdate_option( 'woocommerce_registration_generate_password', 'no' );\n// Show the Company field on customer addresses, so the value collected at signup is visible.\nupdate_option( 'woocommerce_checkout_company_field', 'optional' );\nif ( class_exists( 'WC_Install' ) ) {\n\tWC_Install::create_pages();\n}\n\n// Remove default sample content so the menu stays clean.\nwp_delete_post( 1, true );\nwp_delete_post( 2, true );\n\n// A few sample products, so the shop isn't empty after signing up.\nforeach ( array( array( 'Classic T-Shirt', '25' ), array( 'Canvas Tote Bag', '18' ), array( 'Ceramic Mug', '12' ) ) as $p ) {\n\t$prod = new WC_Product_Simple();\n\t$prod->set_name( $p[0] );\n\t$prod->set_regular_price( $p[1] );\n\t$prod->set_status( 'publish' );\n\t$prod->save();\n}\n\n// Registration Form for WooCommerce: make sure the default form exists.\n$form_id = (int) get_option( '_tgwcfb_form_id' );\nif ( ! $form_id || 'tgwcfb_form' !== get_post_type( $form_id ) ) {\n\t$form_id = wp_insert_post( array( 'post_type' => 'tgwcfb_form', 'post_title' => 'Default form', 'post_status' => 'publish' ) );\n\tupdate_option( '_tgwcfb_default_form_id', $form_id );\n\tupdate_option( '_tgwcfb_form_id', $form_id );\n}\n\n// Sample registration form (free fields only). Markup matches each block's save().\n$req = ' <span class=\"required\">*</span>';\n$blocks = array();\n$blocks[] = '<!-- wp:tgwcfb/first-name {\"label\":\"First Name\",\"fieldWidth\":50,\"required\":true,\"edited\":true} -->\n<p id=\"reg_firstname_field\" class=\"form-row field-width-50\"><label for=\"reg_firstname\">First Name' . $req . '</label><input type=\"text\" placeholder=\"\" class=\"input-text\" name=\"first_name\" id=\"reg_firstname\" autocomplete=\"given-name\"/></p>\n<!-- /wp:tgwcfb/first-name -->';\n$blocks[] = '<!-- wp:tgwcfb/last-name {\"label\":\"Last name\",\"fieldWidth\":50,\"required\":true,\"edited\":true} -->\n<p id=\"reg_lastname_field\" class=\"form-row field-width-50\"><label for=\"reg_lastname\">Last name' . $req . '</label><input type=\"text\" placeholder=\"\" class=\"input-text\" name=\"last_name\" id=\"reg_lastname\" autocomplete=\"family-name\"/></p>\n<!-- /wp:tgwcfb/last-name -->';\n$blocks[] = '<!-- wp:tgwcfb/email {\"label\":\"Email address\",\"required\":true,\"edited\":true,\"confirmEmail\":true,\"confirmEmailLabel\":\"Confirm email address\"} -->\n<p id=\"reg_email_field\" class=\"form-row field-width-100\"><label for=\"reg_email\">Email address' . $req . '</label><input type=\"email\" placeholder=\"\" class=\"input-text\" name=\"email\" id=\"reg_email\" autocomplete=\"email\"/></p><p id=\"reg_confirm_email_field\" class=\"form-row field-width-100\"><label for=\"reg_confirm_email\">Confirm email address' . $req . '</label><input type=\"email\" placeholder=\"\" class=\"input-text\" name=\"confirm_email\" id=\"reg_confirm_email\" autocomplete=\"email\"/></p>\n<!-- /wp:tgwcfb/email -->';\n$blocks[] = '<!-- wp:tgwcfb/password {\"label\":\"Password\",\"required\":true,\"edited\":true} -->\n<p id=\"reg_password_field\" class=\"form-row field-width-100\"><label for=\"reg_password\">Password' . $req . '</label><span class=\"password-input\"><input type=\"password\" placeholder=\"\" class=\"input-text\" name=\"password\" id=\"reg_password\" autocomplete=\"new-password\"/></span></p>\n<!-- /wp:tgwcfb/password -->';\n$blocks[] = '<!-- wp:tgwcfb/billing-company {\"label\":\"Company name\",\"fieldWidth\":50,\"edited\":true} -->\n<p id=\"billing_company_field\" class=\"form-row field-width-50\"><label for=\"billing_company\">Company name </label><input type=\"text\" placeholder=\"\" class=\"input-text\" name=\"billing_company\" id=\"billing_company\" autocomplete=\"organization\"/></p>\n<!-- /wp:tgwcfb/billing-company -->';\n$blocks[] = '<!-- wp:tgwcfb/billing-phone {\"label\":\"Phone\",\"fieldWidth\":50,\"edited\":true} -->\n<p id=\"billing_phone_field\" class=\"form-row field-width-50\"><label for=\"billing_phone\">Phone </label><input type=\"tel\" placeholder=\"\" class=\"input-text\" name=\"billing_phone\" id=\"billing_phone\" autocomplete=\"tel\"/></p>\n<!-- /wp:tgwcfb/billing-phone -->';\n$opts = array( 'Google search', 'Social media', 'A friend', 'Other' );\n$opt_html = '<option value=\"\" selected>Select an option</option>';\nforeach ( $opts as $o ) {\n\t$opt_html .= '<option value=\"' . esc_attr( $o ) . '\">' . esc_html( $o ) . '</option>';\n}\n$blocks[] = '<!-- wp:tgwcfb/select {\"clientId\":\"hearabou\",\"label\":\"How did you hear about us?\",\"placeholder\":\"Select an option\",\"options\":[\"Google search\",\"Social media\",\"A friend\",\"Other\"],\"edited\":true} -->\n<p id=\"select_hearabou_field\" class=\"form-row field-width-100\"><label for=\"select_hearabou\">How did you hear about us? </label><select class=\"tgwcfb-select\" name=\"select_hearabou\" id=\"select_hearabou\">' . $opt_html . '</select></p>\n<!-- /wp:tgwcfb/select -->';\n$blocks[] = '<!-- wp:tgwcfb/checkbox {\"clientId\":\"newslett\",\"label\":\"Send me deals and new arrivals\",\"options\":[\"Subscribe\"]} -->\n<p id=\"checkbox_newslett_field\" class=\"form-row field-width-100\"><label>Send me deals and new arrivals </label><span class=\"tgwcfb-options\"><span class=\"tgwcfb-option\"><input type=\"checkbox\" value=\"Subscribe\" name=\"checkbox_newslett[]\" id=\"checkbox_newslett_subscribe\"/><label class=\"tgwcfb-checkbox-label\" for=\"checkbox_newslett_subscribe\">Subscribe</label></span></span></p>\n<!-- /wp:tgwcfb/checkbox -->';\n$blocks[] = '<!-- wp:tgwcfb/gdpr-agreement {\"clientId\":\"privacy1\",\"label\":\"Privacy\",\"required\":true,\"agreementText\":\"I agree to the privacy policy and terms.\"} -->\n<div id=\"gdpr_agreement_privacy1_field\" class=\"form-row field-width-100\"><label for=\"gdpr_agreement_privacy1\">Privacy' . $req . '</label><div class=\"tgwcfb-gdpr-agreement\" style=\"display:flex;align-items:center;gap:12px\"><input type=\"checkbox\" name=\"gdpr_agreement_privacy1\" id=\"gdpr_agreement_privacy1\" value=\"1\"/><span class=\"tgwcfb-agreement-text\">I agree to the privacy policy and terms.</span></div></div>\n<!-- /wp:tgwcfb/gdpr-agreement -->';\n\nwp_update_post( wp_slash( array(\n\t'ID'           => $form_id,\n\t'post_title'   => 'Store Registration Form',\n\t'post_content' => implode( \"\\n\\n\", $blocks ),\n) ) );\n// After signing up, send the new customer to Account details, where the name and email they entered are already filled in.\nupdate_post_meta( $form_id, '_tgwcfb_redirect_url', '/my-account/edit-account/' );\nupdate_post_meta( $form_id, '_tgwcfb_submit_btn_text', 'Create my account' );\n\n// Demo landing page: the form on its own page, with links to the builder and the customer view.\n$edit_url     = admin_url( 'post.php?post=' . $form_id . '&action=edit' );\n$customer_url = home_url( '/?rfwc_demo_customer=1' );\n$btn          = 'display:inline-block;margin:4px 8px 4px 0;padding:11px 20px;font-size:15px;font-weight:600;border-radius:6px;text-decoration:none;';\n$intro        = '<div style=\"border:2px solid #7f54b3;border-radius:10px;padding:20px 24px;margin-bottom:32px;background:#f8f5fc;\">'\n\t. '<p style=\"margin:0 0 8px;font-size:17px;\"><strong>This registration form was built with Registration Form for WooCommerce.</strong></p>'\n\t. '<p style=\"margin:0 0 14px;\">It adds custom fields to the WooCommerce registration form: name fields, a confirm email field, billing company and phone, a dropdown, a newsletter checkbox and a GDPR consent box. The same form also replaces the default form on the My Account page.</p>'\n\t. '<p style=\"margin:0;\"><a href=\"' . esc_url( $edit_url ) . '\" style=\"' . $btn . 'background:#7f54b3;color:#fff;\">Edit this form in the builder &rarr;</a>'\n\t. '<a href=\"' . esc_url( $customer_url ) . '\" style=\"' . $btn . 'background:#fff;color:#7f54b3;border:2px solid #7f54b3;\">See it as a new customer &rarr;</a></p>'\n\t. '<p style=\"margin:12px 0 0;font-size:13px;opacity:.75;\">\"See it as a new customer\" logs you out and opens My Account. Sign up there to try the form: you will land on Account details, and your company shows under Addresses. To return to the admin, log in with <code>admin</code> / <code>password</code>.</p>'\n\t. '</div>';\n$page_id = wp_insert_post( array(\n\t'post_type'    => 'page',\n\t'post_title'   => 'Create an account',\n\t'post_name'    => 'create-account',\n\t'post_status'  => 'publish',\n\t'post_content' => '<!-- wp:html -->' . $intro . '<!-- /wp:html -->' . \"\\n\\n\" . '<!-- wp:shortcode -->[tgwcfb_registration_form id=\"' . $form_id . '\"]<!-- /wp:shortcode -->',\n) );\nupdate_option( 'rfwc_demo_page_id', $page_id );\ndelete_transient( 'tgwcfb_registration_form_ids' );\n\n// Block editor: no fullscreen (keeps the admin bar link back to the page) and no welcome guide.\nglobal $wpdb;\nupdate_user_meta( 1, $wpdb->get_blog_prefix() . 'persisted_preferences', array(\n\t'core'          => array( 'fullscreenMode' => false ),\n\t'core/edit-post' => array( 'welcomeGuide' => false, 'fullscreenMode' => false ),\n\t'_modified'     => gmdate( 'c' ),\n) );\n\n// Demo-only mu-plugin.\nwp_mkdir_p( WP_CONTENT_DIR . '/mu-plugins' );\nfile_put_contents( WP_CONTENT_DIR . '/mu-plugins/rfwc-demo.php', <<<'MU'\n<?php\n/* Registration Form for WooCommerce Playground demo helpers. */\n\n// \"See it as a new customer\": log out and open My Account.\nadd_action( 'template_redirect', function () {\n\tif ( isset( $_GET['rfwc_demo_customer'] ) ) {\n\t\twp_logout();\n\t\twp_safe_redirect( wc_get_page_permalink( 'myaccount' ) );\n\t\texit;\n\t}\n}, 1 );\n\n// Demo only: keep the WooCommerce registration nonce stable for guests. WooCommerce ties it to the guest\n// session, and in Playground that session can start mid-page, which makes the first signup fail silently.\nadd_filter( 'nonce_user_logged_out', function ( $uid, $action ) {\n\treturn 'woocommerce-register' === $action ? 0 : $uid;\n}, 999, 2 );\n\n// Toolbar links between the live form and the builder.\nadd_action( 'admin_bar_menu', function ( $bar ) {\n\t$form_id = (int) get_option( '_tgwcfb_form_id' );\n\t$page_id = (int) get_option( 'rfwc_demo_page_id' );\n\tif ( is_admin() ) {\n\t\t$bar->add_node( array( 'id' => 'rfwc-demo-view', 'title' => '&#128065; View registration page', 'href' => get_permalink( $page_id ) ) );\n\t} else {\n\t\t$bar->add_node( array( 'id' => 'rfwc-demo-edit', 'title' => '&#9998; Edit form in builder', 'href' => admin_url( 'post.php?post=' . $form_id . '&action=edit' ) ) );\n\t}\n}, 100 );\n\n// Demo only: no \"Leave site?\" prompt in the form builder, so the toolbar link back to the page always works.\nadd_action( 'admin_head', function () {\n\t$screen = get_current_screen();\n\tif ( $screen && 'tgwcfb_form' === $screen->post_type ) {\n\t\techo '<script>(function(){var a=window.addEventListener;window.addEventListener=function(t,f,o){if(t===\"beforeunload\"){return;}return a.call(this,t,f,o);};})();</script>';\n\t}\n}, 0 );\n\n// Demo only: give the Register button a clear button style in the Zakra theme, and show WooCommerce's\n// show/hide password button as an eye icon inside the field (Zakra currently styles it as a blue box).\nadd_action( 'wp_head', function () {\n\techo '<style>.woocommerce .password-input{position:relative;display:block}.woocommerce .password-input input{padding-right:2.75em!important}.woocommerce .show-password-input{position:absolute!important;right:.6em!important;top:50%!important;transform:translateY(-50%);width:24px!important;height:24px!important;min-width:0!important;padding:0!important;margin:0!important;border:0!important;border-radius:0!important;box-shadow:none!important;cursor:pointer;background:transparent url(data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23555%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M1%2012s4-8%2011-8%2011%208%2011%208-4%208-11%208-11-8-11-8z%22%2F%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%223%22%2F%3E%3C%2Fsvg%3E) center/20px 20px no-repeat!important}.woocommerce .show-password-input.display-password{background-image:url(data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22%23555%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M17.94%2017.94A10.07%2010.07%200%200%201%2012%2020c-7%200-11-8-11-8a18.45%2018.45%200%200%201%205.06-5.94M9.9%204.24A9.12%209.12%200%200%201%2012%204c7%200%2011%208%2011%208a18.5%2018.5%200%200%201-2.16%203.19m-6.72-1.07a3%203%200%201%201-4.24-4.24%22%2F%3E%3Cpath%20d%3D%22M1%201l22%2022%22%2F%3E%3C%2Fsvg%3E)!important}.woocommerce .show-password-input::before,.woocommerce .show-password-input::after{display:none!important}.woocommerce-form-register__submit{background:#7f54b3!important;color:#fff!important;border:0!important;border-radius:6px;padding:12px 28px!important;font-weight:600;font-size:16px;cursor:pointer}.woocommerce-form-register__submit:hover{background:#6b4499!important}</style>';\n} );\n\n// Hide admin notices on the plugin's screens.\nadd_action( 'in_admin_header', function () {\n\t$screen = get_current_screen();\n\tif ( $screen && ( 'tgwcfb_form' === $screen->post_type || false !== strpos( $screen->id, 'tgwcfb' ) ) ) {\n\t\tremove_all_actions( 'admin_notices' );\n\t\tremove_all_actions( 'all_admin_notices' );\n\t}\n}, 1000 );\n\n// Stop WooCommerce and the theme from hijacking the first admin visit.\nadd_filter( 'woocommerce_prevent_automatic_wizard_redirect', '__return_true' );\nadd_filter( 'woocommerce_enable_setup_wizard', '__return_false' );\nadd_filter( 'wp_redirect', function ( $location ) {\n\t$location = (string) $location;\n\tif ( false !== strpos( $location, 'page=zakra' ) || false !== strpos( $location, 'setup-wizard' ) || false !== strpos( $location, 'page=wc-setup' ) ) {\n\t\treturn admin_url( 'post.php?post=' . (int) get_option( '_tgwcfb_form_id' ) . '&action=edit' );\n\t}\n\treturn $location;\n} );\nMU\n);\n\nflush_rewrite_rules( false );\n"
    },
    {
      "step": "login",
      "username": "admin"
    }
  ]
}
