Display WooCommerce Product Variations Dropdown on the Shop Page

Remi | September 28, 2016 | in WooCommerce

Riaan, my fellow colleague at Automattic asked me if I had a snippet to display the variations dropdown select on the shop page for variable products so that customers can shop variable product directly from an archive page without having to visit the product page… and I didn’t have such a snippet. So I built it! (that was a long sentence right?)

The idea here is pretty simple, when you visit the shop page, or an archive page, the code checks the product type and if it’s equal to variable, the “Select Options” button is replaced by the regular add to cart button for variable products. In other words, it displays the dropdown selects for the product attributes and the add to cart button on the shop page for all variable products.

woocommerce-dropdowns-selects-on-archive-page

If you want to use this snippet, simply copy and place it in the functions.php file in your theme folder!

The author

About the author Remi: Hey! My name is RĂ©mi Corson, i'm a WordPress Expert Developer, i create high level themes and plugins, and i provide free stuff every week on this website!

10 Comments

  1. mgason

    Hi,
    I added the code. I am using Storefront theme from woocommerce. I get a selector and quantity field etc but none of my selectors actually contain the variations. Any ideas?

  2. javied

    Hello Remi,

    I tried your code.. but its showing me blank page.

    I have a question,
    Is it possible to show the varitions dropdown based on product id .If yes how can I achieve that.

    Thanks

  3. javied

    Hello Remi,

    I have created a custom shortcode to show products based on id with an image, description,price and add to cart url which send the product directly to cart. Now I have created a varibale product, and added its id in my shortcode. Would you gudie me how can i show the variation options dropdown for that product and add to cart url which can send this product direcly to cart with all the variations seclected.
    However I tried your code. And it breaks my website, simply a blank page is coming below header.

    This is the my custom shortcode:-
    function ayu_magazine_subscription_woo_products_shortcode ( $atts ) {
    global $post; $thePostID = $post->ID;

    $atts[ ‘ids’ ] = explode( “,”, $atts[ ‘ids’ ] );
    extract ( shortcode_atts (array (
    ‘ids’ => $atts[ ‘ids’ ]
    ), $atts ) );
    ///////$atts[ ‘parent’ ] = explode( “,” $atts[ ‘parent’ ] );
    ///////extract( $atts );

    $output.=”;
    $output.=’

    ‘;

    foreach($atts[‘ids’] as $productId)

    {
    // print_r($productId);
    $product = wc_get_product( $productId );

    if($productId==”5207″)
    {
    $title_head=”Digital”;
    }elseif($productId==”5208″)
    {
    $title_head=”Print”;
    } elseif($productId==”5206″)
    {
    $title_head=”Combo”;
    }
    else{
    $title_head=$product->get_title();
    }

    $output.=”;
    $output.=”.$title_head.”;
    $output.=”;
    /*$output.=’

    ‘. $product->get_image($size = “full”).’
    ‘;*/
    $output.=’‘. $product->get_image($size = “full”).’‘;
    $post_content = get_post($productId);
    $content = $post_content->post_content;
    $output.=”.apply_filters(‘the_content’,$content).”;
    $output.=”;
    $output.=”.$product->get_price_html().”;
    $output.=”;

    $output.=”;
    $output.=”;

    $output.= ‘Subscribe‘;
    $output.=”;

    $output.=”;

    }

    $output.=”;

    return $output;

    }
    add_shortcode(‘magazine_subscription_products’, ‘ayu_magazine_subscription_woo_products_shortcode’);

    Guide me how can i show variations options also through this code.

    Thanks

  4. eni

    Hello Remi! Thanks for your hard work.I used your code and the result is that i get a drop-down phrase “choose” only and on the left a small text “brand” but i have weight as variable,the button add to cart or select options is missing also.Any idea would be helpful.Below is a pic of my site.Thank you!

    https://postimg.org/image/a48x8saaf/

Leave a reply