admin管理员组

文章数量:1122846

I use this code in Wordpress (Woocommerce) to change products link:

function jpb_custom_meta_permalink( $link, $post ){
    $post_meta = get_post_meta( $post->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', 'jpb_custom_meta_permalink', 10, 2 );

function append_sku_string( $link, $post ) {
  $post_meta = get_post_meta( $post->ID, '_sku', true );
      if ( 'product' == get_post_type( $post ) ) {
        $link = $link . $post_meta;
        return $link;
     }
}
add_filter( 'post_type_link', 'append_sku_string', 1, 2 );"

This code changes products permalink to something like this:

But what I want is:

Any suggestion?

本文标签: Woocommerce products permalink based on SKU