Skip to content

Add to Cart button instead of Select Options on Shop Pages for default variation

I only use two Variations, One is a Physical Product the other is a Digital Version, the physical product is the default variation, I want to be able to use an Add to Cart on the product list pages for the default variation (physical product).

I found an *almost solution, I am not sure how to get the default variation product ID.

`function filter_woocommerce_loop_add_to_cart_link( $link, $product ) {

if ( is_shop() && $product->product_type === 'variable' ) {
    $product_id = $product->get_id();
    $product_sku = $product->get_sku();

      $link = '<a rel="nofollow" href="?add-to-cart=' . $product_id . '" data-quantity="1" data-product_id="' . $product_id . '" data-product_sku="' . $product_sku . '" class="button product_type_simple add_to_cart_button ajax_add_to_cart add-to-cart" aria-label="Add to cart"><em>Add to cart</em></a>';

}

return $link; `