Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter A.malakar

    (@ayushmalakar)

    Never mind I got the hand of it
    Here is the sample Code

    add_action('woocommerce_after_shop_loop_item', 'show_more_color');
    function show_more_color() {
        global $post, $product;
        if ($product->product_type == 'variable') :
            // Get product variations
    
            $variations = $product->get_available_variations();
            $testVariable = $variations[0];
            $check = $testVariable['attributes']['attribute_color'];
            if ($check) {
                echo '<a href=" ' . get_permalink($post->ID) . '">More Color</a>';
            }
    
        endif;
    }

    Hello,
    $product->product_type returns null for me when I do:
    $product = new WC_Product( $product_id );
    Im expecting simple or variable, but it returns null.
    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Check if product is has a varation or not’ is closed to new replies.