• Resolved customlogoshop

    (@customlogoshop)


    At the moment, my SKU with main product and variations is this ‘LP/24410/RA/R/SL/B-b/rw/none’. You can see the dash that joins them together, but I would like to change it to a forward slash.

    Is there a way to do this?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support jlareauxskyverge

    (@jlareauxskyverge)

    Hi there!

    Thank you so much for using our Product SKU Generator plugin. I’d be happy to help answer your questions about it!

    We have a hook available that you could use to accomplish this called wc_sku_generator_sku.

    A filter like the one below should do the trick ??

    <?php
    
    // Replace hyphen with forwardslash in product SKUs
    function sv_wc_sku_generator_sku( $product_sku, $product ) {
        $product_sku = str_replace( '-', '/', $product_sku );
        return $product_sku;
    }
    add_filter( 'wc_sku_generator_sku', 'sv_wc_sku_generator_sku', 10, 2 );

    Do you think the above will work for you?

    Thread Starter customlogoshop

    (@customlogoshop)

    Hmm that didn’t work for me. Here’s a screenshot of my code, I also use the add a ‘/’ for spaces, so maybe it’s a conflict?

    https://pasteboard.co/M1Q3WJBoZWfM.jpg

    Also I wondered if I call an unwanted attribute SKU ‘-‘, can you provide a code to remove that from the SKU?

    Reason being is I have a variation attribute called ‘none’ and I don’t want this to add something to the SKU. I can’t leave a slug blank, so is there a way for me to call it ‘-‘ but then have a function that removes it from the SKU? This would be the final piece of my SKU puzzle!

    Thread Starter customlogoshop

    (@customlogoshop)

    Actually, an underscore I have chosen for an attribute

    LP/24410/RA/R/SL/N-rw/n/_

    So you can see from the – is my attributes, would need – changing to / and then at the end, somehow remove the _ from a slug name I have chosen.

    Ideally it would be good to remove the / before it too as I don’t want that attribute adding to the SKU if that makes sense.

    Optimal end result would be LP/24410/RA/R/SL/N-rw/n

    Thread Starter customlogoshop

    (@customlogoshop)

    function sv_wc_sku_generator_sku( $product_sku, $product ) {
        $product_sku = str_replace( '-', '/', $product_sku );
    	
        return $product_sku;
    }
    add_filter( 'sv_sku_generator_sku_separator', 'sv_wc_sku_generator_sku', 10, 2 );
    
    

    This worked! ?? Now I just need to get rid of the dash that I’ve used in an attribute slug – can you help please?

    Plugin Support jlareauxskyverge

    (@jlareauxskyverge)

    Hey there,

    My apologies! I missed the variation part. That would hook onto wc_sku_generator_variation_sku instead of wc_sku_generator_sku.

    I’ve modified my previous filter to use the variation hook:

    <?php
    
    // Replace hyphen with forwardslash in product SKUs
    function sv_wc_sku_generator_sku( $product_sku, $product ) {
        $product_sku = str_replace( '-', '/', $product_sku );
        return $product_sku;
    }
    add_filter( 'wc_sku_generator_sku', 'sv_wc_sku_generator_sku', 10, 2 );

    Can you give this filter a try and let me know if it works for you?

    Thank you!

    Thread Starter customlogoshop

    (@customlogoshop)

    I’ll try this tomorrow ?? so the hyphen to slash issue is resolved. Now I just need a way to make an underscore blank. The underscore will come from my attribute slug.

    I’m thinking of a way that I can make an attribute disappear from my SKU (I have a variation that I wouldn’t like added to the sku when selected)

    So I am thinking if I call the slug ‘_’, is there a code I can use to remove it from my variation SKU?

    Thread Starter customlogoshop

    (@customlogoshop)

    Hmmm not working

    Thread Starter customlogoshop

    (@customlogoshop)

    function asv_wc_replace_variation_sku_separator( $separator ) {
    	return '/';
    }
    add_filter( 'wc_sku_generator_sku_separator', 'asv_wc_replace_variation_sku_separator' );

    This worked! Now I just need to remove the underscore from the end of the sku, which is applied by an attribute slug. Can you help?

    Thread Starter customlogoshop

    (@customlogoshop)

    All sorted!

    If anyone is interested in removing a slug from an attribute, try this

    // Remove slug from SKU
    
    function sv_wc_sku_generator_variation_sku( $variation_sku ) {
    	$variation_sku = str_replace( 'slug', ' ', $variation_sku );
    	return $variation_sku;
    }
    add_filter( 'wc_sku_generator_variation_sku', 'sv_wc_sku_generator_variation_sku' );
    Plugin Support jlareauxskyverge

    (@jlareauxskyverge)

    Hey there,

    Thank you so much for sharing what your solution was!

    I hope we were helpful along the way ??

    Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How can I change the dash after parent product SKU to a forward slash instead?’ is closed to new replies.