title: Woocommerce. Add product SKU to url before slug
body: <p>I am trying to add the woocommerce product SKU to the URL of the product. I have followed this guide (<a href="http://www.themelocation.com/how-to-add-sku-to-product-url-in-woocommerce/" rel="nofollow">http://www.themelocation.com/how-to-add-sku-to-product-url-in-woocommerce/</a>) which works, however I need the SKU to come before the slug.</p>
  
  <p>Like this:
  <a href="http://test.com/shop/category/sku-product" rel="nofollow">http://test.com/shop/category/sku-product</a></p>
  
  <p>I have amended the code in the above link to successfully get this order in the wordpress admin area, however as you might predict, it is causing all the products to 404.</p>
  
  <p>How do I go about fixing this? Some kind of htaccess redirect rule?</p>
  
  <p>Here is my amended code:</p>
  
  <pre><code>function custom_meta_permalink( $link, $post ){
  
      $post_meta = get_post_meta( $post-&gt;ID, '_sku', true );
      if( empty( $post_meta ) || !is_string( $post_meta ) )
          $post_meta = '';
      $link = str_replace( '!!custom_field_placeholder!!', $post_meta, $link );
      return $link;
  
  }
  add_filter( 'post_link', 'custom_meta_permalink', 10, 2 );
  
  function append_sku_string( $link, $post ) {
  
      $post_meta = get_post_meta( $post-&gt;ID, '_sku', true );
      if ( 'product' == get_post_type( $post ) ) {
          $end = substr($link, strrpos($link, '/') + 1);
          $beg = substr($link, 0, strrpos( $link, '/' ));
          $link = $beg . '/' .$post_meta.'-'.$end;
          return $link;
      }
  
  }
  add_filter( 'post_type_link', 'append_sku_string', 1, 2 );
  </code></pre>