This problem became to be a solution for another problem which is
How to create your own product page
after too much searching, I found out a function $product->get_available_variations() ;
which returns an array of available variations and their attributes. and got product id from $product->get_id();
.
I used $pro_vari[0][attributes] [attribute_pa_ptfc];
to get my custom attribute slug and then used it to get exact variable_id
for the variation by
$ft_variation_id= $pro_vari[0][variation_id] ;
in last I created an add to cart url which directly took me to the checkout (skipping cart page)
<a href="/checkout/?add-to-cart=<?php echo $current_product_id; ?>&variation_id=<?php echo $ft_variation_id; ?>&attribute_pa_ptfc=finance-terms">Checkout Now</a>
this created following link:
checkout/?add-to-cart=4881&variation_id=5022&attribute_pa_ptfc=finance-terms
In my case I only have 2 variations so used IF condition for pro_var[0]
and pro_vari[1]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…