5
votes

I have set up a woocommerce store and I add some variations to some products. Each variation has its own sku number, but for some reason they are not showing up on the products overview panel. Is there any way were I can add them or somebody could show me the right direction to go. Also, if I try to search the variation, is not showing up the product were is located. Do I have to register the variation sku somewere? Is this comming by default with woocommerce or not?

Thanks!

enter image description here

This is how I have set up the variations:

enter image description here

3
I think you are using underscore in SKU thats the reason why your products does'nt showing SKU.Jaswinder Kaur
Nop... there are products with _ and they are simple products and they show up.. and there are products with _ and without it, as variable products and they do not show up...Mario Sanchez Maselli
Requesting question closing [Flag] as its having nothing to deal with code issues. Even person asking is not active on problem replies.Navnish Bhardwaj
If you don't know the answer it doesn't mean it's not code related. Found this bug open on githubhttps://github.com/woothemes/woocommerce/issues/1734Mario Sanchez Maselli

3 Answers

2
votes

Ok given that nobody came with an aswer I had to dig a little bit myself :D So here is the solution that I found for the moment.

On file class-wc-admin-post-types.php which is located on woocommerce/includes/admin

You have to modify some code on line 277

case 'sku' :

    $type = (get_class($the_product));

    if( $type == 'WC_Product_Variable' ){

        $available_variations = $the_product->get_available_variations();

        echo '<strong> Variations: </strong>' . count($available_variations) . '<br><br>';

        for ($i = 0; $i <  count($available_variations); $i++ ) {

            echo ($available_variations[$i]['sku']) . '<br>';
        }
    }
    else {
        echo $the_product->get_sku() ? $the_product->get_sku() : '<span class="na">&ndash;</span>';
    }
break;

And now you can get something like this: When you have variations on your product you will show the amount of variations and all of the available sku's and if is not a variable product you will only show the sku.

Now I'm thinking that I will probably modify also the stock colum and show the amount of stock on each one of them.

Hope this helps someone else. And thanks for the ones who tried to help!

enter image description here

Ok... so I added the support for stock nothing much different than then previous code... So on the same document now on line 344, you can add this.

case 'is_in_stock' :

            $type = (get_class($the_product));

            if( $type == 'WC_Product_Variable' ){

                $available_variations = $the_product->get_available_variations();

                echo '<strong> Variations stock: </strong> <br><br>';

                for ($i = 0; $i <  count($available_variations); $i++ ) {


                    if ( $available_variations[$i]['is_in_stock'] == 0 ) {
                        echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
                    }else {

                        echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>';

                    }
                    if ($available_variations[$i]['variation_is_active']) {
                        echo ' &times; ' . $available_variations[$i]['max_qty'] . '<br>' ;
                    }
                }
            } else {

                if ( $the_product->is_in_stock() ) {
                    echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>';
                } else {
                    echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
                }

                if ( $the_product->managing_stock() ) {
                    echo ' &times; ' . $the_product->get_total_stock() ;

                }
            }
            break;   

An you get something like this:

enter image description here

For more information check out link below. Resume: this approach can have some performance problems... carefull on how many product variations do you have.

https://github.com/woothemes/woocommerce/issues/9396

1
votes
add_action( 'woocommerce_single_product_summary', 'dev_designs_show_sku', 5 );
function dev_designs_show_sku(){
    global $product;

    if ( $product->is_type( 'variable' ) ) {
      $available_variations = $product->get_available_variations();
      for ($i = 0; $i <  count($available_variations); $i++ ) {    
          echo 'SKU: ' . ($available_variations[$i]['sku']) . '<br>';
      }
    } else {
      echo 'SKU: ' . $product->get_sku();
    }
}
-1
votes

Just remove the IF conditional check that surround the HTML out of the SKU from the meta.php file. Around LINE 18.

The file is in the WC plugins/templates folder.

OR

Just from this -> $product->get_sku() From the IF statement as that is causing the issue.

It returns an empty string is why the IF conditional is never satisfied.

In addition, the reason why this happens is if the parent product does not have a SKU, and only your variables have, this issue will occur. Hence my comment up top stating it returns empty string as it tries to pull from the parent first. another words if you have set SKU to the parent and variables, everything will work even without modification of the code I mentioned.