Support » Plugin: WooCommerce » Variation ID is 0

  • Resolved amc11

    (@amc11)


    Hi,

    Im having issues with orders that do not pick up the variation id, its 0
    on some orders some times.

    Why is this happening?

    Thank you!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter amc11

    (@amc11)

    I can see the order in admin, including its variation.
    But with code I cannot get the correct variation id. Its always zero.

    Is there any way around this?

    lorro

    (@lorro)

    What code are you using?

    If its a big chunk of code, use pastebin and put the link here.

    Thread Starter amc11

    (@amc11)

    Hi,

    Thank you!

    Well, I run this simple code and the variation id is 0.

    Not for all orders, it just happens sometimes.
    How can I fix this?

    function get_variation_id() {
    		$order = new WC_Order(191594);
    		$items = $order->get_items();
    		
    		foreach ( $items as $item ) {	
    			print $item['variation_id'];
    		}
    }
    add_action('wp_footer', 'get_variation_id');
    • This reply was modified 1 year ago by amc11.
    lorro

    (@lorro)

    I think your code should check that the $item is a varible product, otherwise it won’t have a variations. Note that any shipping and refunds will also be order items.

    You can use print_r( $item ); in your code to try to see what the item is.

    Thread Starter amc11

    (@amc11)

    Here is a section of that array:

    [750] => WC_Order_Item_Product Object
            (
                [extra_data:protected] => Array
                    (
                        [product_id] => 0
                        [variation_id] => 0
                        [quantity] => 1
                        [tax_class] => 
                        [subtotal] => 0
                        [subtotal_tax] => 0
                        [total] => 0
                        [total_tax] => 0
                        [taxes] => Array
                            (
                                [subtotal] => Array
                                    (
                                    )
    
                                [total] => Array
                                    (
                                    )
    
                            )
    
                    )
    
                [data:protected] => Array
                    (
                        [order_id] => 191594
                        [name] => Haro Downtown 16" - HARO DOWNTOWN 16 SG RED BMX 16 8
                        [product_id] => 21480
                        [variation_id] => 0
                        [quantity] => 1
                        [tax_class] => 
                        [subtotal] => 1996
                        [subtotal_tax] => 499
                        [total] => 1996
                        [total_tax] => 499
                        [taxes] => Array
                            (
                                [total] => Array
                                    (
                                        [1] => 499
                                    )
    
                                [subtotal] => Array
                                    (
                                        [1] => 499
                                    )
    
                            )
    
                    )
    
    .......
    • This reply was modified 1 year ago by amc11.

    @amc11 have you found a solution to this?

    I seem to have a similar issue that is very odd. In one order a variation can be added fine but then another variation’s _variation_id is set to 0 in the order meta.

    Looking at the product and database the variation looks fine so I’m not sure why certain variations don’t add correctly.

    It seems to happen randomly as if I test adding the same product variations to a test order it all goes through fine.

    So even if I update plugins, clear caches, etc. it’s difficult to test if the issue is sorted because I don’t have anything specific to test for.

    Hi @amc11 I’m having the same issue. Did you ever find a solution? Thank you so much!

    Just to update on my issue. I found that the cause was the customer adding multiple options to the cart too quickly on the product page. They would add the second option before the page fully loads resulting in the variation id not being added.

    This is more a workaround as I realize this shouldn’t happen but I forced a redirect to the cart page after any option added forcing the customer to go back into the page to add additional options. This gave time for the page to load and haven’t had the issue since.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Variation ID is 0’ is closed to new replies.