I’ve added SKU to Woocommerce products permalinks, but I have a small issue
-
Hello
I use code number 1 in functions.php and number 2 in .htaccess to get Products Permalink based on SKU.
Something like this: xyz.com/product-title/#sku
How could I remove “#” from the permalink (in front of the sku)?
When I remove it manually from the code number 1 without changing the code number 2, the links will become correct but they go to 404 page.
Also what should I do if I wanted to change my products URLs to something like this: xyz.com/sku/product-title/Code 1
"function jpb_custom_meta_permalink( $link, $post ){
$post_meta = get_post_meta( $post->ID, '<insert your meta key here>', true );
if( empty( $post_meta ) || !is_string( $post_meta ) )
$post_meta = '<insert your default value (could be an empty string) here>';
$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 );"
===============================================
Code 2
"<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^whisky/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ ?sku=$1&product=$2 [NC,L]
</IfModule>"
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.