skip to Main Content

I’ve looked for the solution to this but nothing seems to be working.

I have an SKU within a span with a class of “sku”. Some of the SKUs have periods before the SKU to allow for adding more than one product with the same SKU.

I’d like to hide the periods when the SKU is displayed though.

This is my code:

<span class="sku">..THESKU</span>

And this is the jQuery I am using:

<script>
    $('span.sku').html($('span.sku').html().replace('.',''));
</script>

Is the right, or am I missing something? Thanks.

2

Answers


  1. Chosen as BEST ANSWER

    I just wanted to give an update with this. I still couldn't get the periods to hide, but I found a way to have duplicate SKUs so there was no longer a need for this. Thanks for all your help.

    If anyone has a similar issue, the code I used is below which I added to the themes functions file.

    add_filter( 'wc_product_has_unique_sku', '__return_false', PHP_INT_MAX );


  2. Your code will only replace one dot '.'. You can use regex to remove all the dots instead:

    const skus = $('span.sku');
    
    $('span.sku').each(function() {
      const text = $(this).html();
      const cleaned = text.replace(/./g,'');
      $(this).html(cleaned);
    })
    

    Hope this helps!

    EDIT: Updated as suggested by @Taplar

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search