• I’ll try keep as brief as I can – developing my own plugin which creates variable products on the fly.

    When created and then viewed on frontend I get the “This product is currently out of stock and unavailable.” message. Everything else is all good and product appears fine in admin etc, I’m running
    WC_Product_Variable::sync( $new_parent_product_id );
    and it’s doing all that I’d expect. If I update the product in admin without altering anything then it displays fine on the frontend.

    Working back through the product templates to variable.php I see that $available_variations in there is empty. Digging into class-wc-product-variable.php noticed when I log $this->children in there the get_children function a product that’s not displaying returns:

    $this->children in get_children : Array
    (
        [all] => Array
            (
            )
    
        [visible] => Array
            (
                [0] => 550
                [1] => 551
            )
    
    ) 

    Once I save/update in the admin and it displays right I get:

    $this->children in get_children : Array
    (
        [visible] => Array
            (
                [0] => 550
                [1] => 551
            )
    
        [all] => Array
            (
                [0] => 550
                [1] => 551
            )
    
    )

    At this point I’m stumped and get a bit lost in the code! I just can’t see what’s causing the [all] array to be empty (or why array keys are reversed)??

    Massively appreciate any further pointers, have been stumped for hours & hours on this!

    Cheers,

    Steve

Viewing 1 replies (of 1 total)
  • Thread Starter SteveHoneyNZ

    (@stevehoneynz)

    Worked it out finally – I was using the get_available_variations function within my code to check if a variation existed, but running that on a newly created parent product before I ran the sync function for the first time was creating the malformed array, which was then being passed into the sync function when first run. Putting in a check for that solved things.

    • This reply was modified 8 years, 4 months ago by SteveHoneyNZ.
Viewing 1 replies (of 1 total)
  • The topic ‘Issue with display off variable products created programattically’ is closed to new replies.