title: WooCommerce Registration Shortcode - Error messages problems
body: <p>I am currently creating a widget to display the registration form on a WordPress website that uses WooCommerce. For now, I only have 3 basic fields which are email, password, repeat password. I'm looking forward to add more WooCommerce fields, but want to solve that problem before jumping to the next step.</p>
  
  <p>I'm having some problems with the messages output (wrong password, account already exists, etc).</p>
  
  <p>I searched on the web and there was no shortcode already built for WooCommerce registration, beside their registration page. So I went ahead and created a shortcode, with a template part.</p>
  
  <pre><code>function custom_register_shortcode( $atts, $content ){
      global $woocommerce;
      $form = load_template_part('framework/views/register-form');
      return $form;
  }
  add_shortcode( 'register', 'custom_register_shortcode' );
  </code></pre>
  
  <p>This is a snippet I use to get the template part inside a variable, since the default function would "echo" the content instead of "returning" it.</p>
  
  <pre><code>function load_template_part($template_name, $part_name=null) {
      ob_start();
      get_template_part($template_name, $part_name);
      $var = ob_get_contents();
      ob_end_clean();
      return $var;
  }
  </code></pre>
  
  <p>So, the problem is, when I call <code>woocommerce_show_messages</code> or <code>$woocommerce-&gt;show_messages();</code> from my template part, nothing is showing, or if it is, it shows at the top of the page.</p>
  
  <p>I did try to put the calls inside my shortcode function:</p>
  
  <pre><code>function custom_register_shortcode( $atts, $content ){
      global $woocommerce;
      $woocommerce-&gt;show_messages(); 
      $form = load_template_part('framework/views/register-form');
      return $form;
  }
  add_shortcode( 'register', 'custom_register_shortcode' );
  </code></pre>
  
  <p>Doing so, the message output inside the <code>&lt;head&gt;</code> tag, which is not what I want.</p>
  
  <p>I tried to do the same trick with <code>ob_start()</code>, <code>ob_get_contents()</code> and <code>ob_clean()</code> but nothing would show. The variable would be empty.</p>
  
  <p>I also did try to hook the <code>woocommerce_show_messages</code> to an action as saw in the core:</p>
  
  <p><code>add_action( 'woocommerce_before_shop_loop', 'woocommerce_show_messages', 10 );</code> </p>
  
  <p>For something like:</p>
  
  <p><code>add_action( 'before_registration_form', 'woocommerce_show_messages');</code> </p>
  
  <p>And I added this in my template-part:</p>
  
  <p><code>&lt;?php do_action('before_registration_form'); ?&gt;</code></p>
  
  <p>But I still can't manage to get the error messages show inside the box. It would always be inserted in the <code>&lt;head&gt;</code></p>
  
  <p>I will share final solution when everything is done.</p>
  
  <p>Thanks for your time, </p>
  
  <p>Julien</p>