Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 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 Reply

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]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...