Skip Navigation

[Resolved] Create product with Cred and affect a booking type

This support ticket is created 7 years, 2 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: America/Toronto (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Pat 7 years, 2 months ago.

Assisted by: Meagan Hanes.

Author
Posts
#493162

Pat

Hello,

I'm using Cred to create new products in front end and needs to define the product as "bookable" (in the list were we can find simple, variable, affiliate ...)
How can I do this ?
Regards
Pat

#493209

Hi Pat!

Creating custom product types for WooCommerce products is something that requires custom code to do, and should be done according to WooCommerce's approved "way of doing things".

I was able to find this recent tutorial on creating custom product types: hidden link

I believe that if the new custom product type is created using WooCommerce hooks, Toolset should pick it up automatically when you add the field to your CRED product creation form.

Give it a try and let me know how it goes!

Meagan

#493224

Pat

Hi Meagan,

Not sure the article helps as it is more on the creation of a new product type and not how to be able to chose a product type within Toolset.

Looking at your documentation, it is said that Cred can create products for simple and affiliate (which means, Toolset is able to assign a relationship into the database wp_term_relationship.

Concerning the bookable type, it is more or less a simple product and should be manageable by Toolset the same way as simple and affiliate product creation.

Could you dig a little more on this please and see if there is something special to do for this.

For your info, I have checked in the database and you have a first table wp_terms where the different product types are stored (ie : simple : id=2, bookable: id=6 ...) and then, you have the wp_term_relationships table where you have the assignment of all product to a product type like :

object_id | term_taxonomy_id | term_order
29 | 6 | 0
Where 29 is the product ID and 6 the product type term for a bookable product

If no possibility to manage this within Toolset, the last solution would be to create a specific record in the wp_term_relationships table using the product ID that have been created by the Cred and affecting 6 as term_taxonomy_id

Let me know
Regards
Pat

#493235

Thanks for the clarification.

I've had a look at our documentation (https://toolset.com/documentation/user-guides/creating-woocommerce-products-using-cred-forms/) and see that it says we only support Simple Products and External/Affiliate product creation using CRED forms.

It may be that, despite the simplicity of the Booking custom product type, Toolset is simply not able to create products that are not the two listed above.

What plugin or code are you using which creates this custom product type?

I'll reach out to my colleagues to see if any of them know a way to accomplish this, however you may be able to create a custom function that creates the appropriate record in wp_term_relationships as you describe. Our CRED Commerce API (https://toolset.com/documentation/user-guides/cred-commerce-api/) contains a number of hooks you can use to create this record.

Thanks,
Meagan

#493249

Pat

Hi Meagan,
I understand the "simple product" limitation as with variable products, you need to create several posts (one for each variation). For me, bookable products are the same way as simple products. Again, if Toolset is able to manage both simple and affiliate products that required different terms id in the wp_term_relationships table, this means Toolset is able to manage the creation of this type of record inside this database table. So, I just need to change the product simple (term_id 2) to bookable (term id 6) in this record creation.

On the other hand, I agree this could be achieved with Cred API (cred_save_data for example).
In this condition, I'm not sure which function I need to use to manage the creation of a new record in a specific database table.

Regards
Pat

#493276

While I agree that in theory your bookable product type and a simple product are structurally the same, the issue comes with the fact that this bookable product type is a custom product type, and I imagine our tool is hard-coded to the two accepted product types in place of looping through all product types.

You would use $wpdb to manage adding or modifying the record directly in the database. More info: https://codex.wordpress.org/Class_Reference/wpdb

Hook into cred_save_data, use $wpdb to find the automatically-created record in wp_term_relationships and replace its product type term.

Let me know if this works!

Meagan

#493288

Pat

Hi Meagan,

OK, I will follow your advice and use $wpdb to manage this specific table thanks to a cred_save_data
Thanks for your support
Pat

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.