Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

php - "Variation" is a required field

I am creating a farmhouse website, farmhouses will be available for rent and for purchasing. for that, I am writing my own product url.

<a href="/cart/?add-to-cart=4881&variation_id=5020">Checkout Now</a>

there are only 2 variations and they have price and they are "in-stock"

when I go to url it shows error on cart page

"Purchase type is a required field"

where Purchase type is the attribute on which variations are created.

What is mean by "is a required field" when the required field (regular price) is filled.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...