i have a WooCommerce store with mostly variable products, i want that the users can add to the cart directly from the shop page without having to go to the single product page. for that im creating a function to make a custom button with the link of the products:
function custom_add_to_cart_redirect() {
global $product;
$product_id = $product->id;
echo '<a rel="nofollow" href="http://localhost/alanicwordpress/shopping-car/?add-to-cart='.$product_id.'&variation_id='.$variation.'&attribute_pa_size=size" class="button product_type_variable add_to_cart_button"><span class="lnr lnr-cart"></span></a>';
}
add_filter( 'woocommerce_after_shop_loop_item', 'custom_add_to_cart_redirect' );
but when i click in the button send my to the cart and give a warning that a must select product options because is a variable product. i want to know how to obtain the variation id to add it to the link im building. or is there is a way to put the default variation that have every product an add that to the cart when the user click the button.