Skip Navigation

[Resolved] Cred commerce with price calculated

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Pat 6 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#605771

Pat

Hello,

I'm building a site with Toolset and would like to use Cred commerce to create virtual product. Until then, no issue, but now, I would like the product price to be calculated thanks to some choice made by the user inside the formular.

Let's take an example :

The user arrives in the page where the Cred commerce is displayed. He can chose between different courses.
Depending on the result of the choice, the price will be different.
I know that normally, at that point, I have to create all needed products in WC and use a field to manage the relation between Cred and the product that will be associated. But I would prefer to be able to have only one product and pass the product price thanks to the choice result inside Cred.

As a basic request, this could be the same solution than if you want to propose a Cred commerce form and that the user is able to enter by himself the price he wants to pay !

Regards
Pat

#605946

With CRED you can manipulate Simple and External Products, and this is subject to several restrictions.
https://toolset.com/documentation/user-guides/creating-woocommerce-products-using-cred-forms/

I am sure you know that already, I just want to remind that this is a "work in progress" and not a "set in stone" compatibility yet.
Lot's of work has to be done in this matter.

As for the calculation, this is not something that CRED or (AFAIK) WooCommerce offers out of the box.
What you can do is use custom JS, where you get the values from let's say 2 Generic Fields, and perform your calculation so to update the target Field with the result.

Or, you can do the calculation on the server side after the form is submitted, with cred_save_data() as example:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
Within this hook you can manipulate values from the $_POST and update the target with update_post_meta() function of WordPress.
https://codex.wordpress.org/Function_Reference/update_post_meta
Calculations here would be made with PHP math operators.

Right now you can bind a static product or let the user choose a product according a Custom Field which you need to add to the Form.
Then in the Commerce settings you can choose that field as the source for the Product ID to be used.

With this method you can already have "different" products available, but not a "pay as you want" product, which does not exist within WooCommerce.

I think this is a request that should be added to WooCommerce first, eventually.
Then, it could be used in CRED too.

Or, you can neglect to use WooCommerce and simply bind a PayPal event to the Form, after you submit it.
Use the Custom Field where the user entered his desired payment value as the value to be passed over to PayPal (For that, you need to consult the PayPal API).

Our major goal related to this, in future, is to make WooCommerce fully compatible with CRED (or vice versa, if you prefer 🙂 )

This will take some time, and after, we could re-think this request. But it would be easier if the core (WooCommerce in this case) would offer the ability to "pay as you want", which is, AFAIK, not possible with it now.

#605975

Pat

Hi Beda,

Thanks for your explanations.

I understand this is something first related to WC and I have raised this request to them in order to know if this is currently integrated in their todo list or not.

Depending of their answer, I will see if this is worth trying to setup something with the Cred hooks.

Thanks
Pat