Skip Navigation

[Resolved] Create Relationship between custom post type and woo commerce product

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

Our next available supporter will start replying to tickets in about 1.84 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by Nigel 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1121310

In my site there is one custom post type obituaries.
Using woocommerce product facility I want to create flower shop.
So I want to create relationship between obituaries and flower shop. So If customer place order for flower that flower should be linked with that obituary.
Can you please help me for creating relationship between obituary and flower. I have created relationship(One to Many) but it is not working.

#1121641

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

We have a current unresolved issue where using WC Orders in post relationships is not working. It is with the developers and I expect it to be resolved soon, but if you try to set up such a relationship at the moment you will likely encounter problems (JS errors on the post edit screen when making the connection).

You say that you have created a one-to-many relationship between Obituaries and flowers but it is not working.

What does "not working" mean? What are you expecting to happen, and when?

It sounds like you are connecting the product (flowers) rather than the orders to obituaries, is that right?

If you edit an obituary and at the bottom of the edit screen add a related flower product, does that work? That is, does the relationship itself work?

It sounds like you are expecting something to happen during the order process, could you describe what?

And once you have established a connection between the posts, how do you intend to use it (that might affect how you want to set this up in the first place)?

#1122403

Obituary is the custom post type which i have created using toolset plugin.
To Display flowers under obituary i have created a view.
Now I am explaining what i wanted to do.
Where user click on Obituary under flower tab it will display all the flowers over there. Where user click on Add to Cart button I want to link flower with Obituary. So vendor can able to see which flower is linked with which obituary. User can send more than one flower to one obituary.

#1122755

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I need some more details about how exactly you would expect this to work to give specific advice about how to implement it.

I understand that the final objective is that it should be possible to visit an obituary post and on that post see the flower products that have been bought in relation to that obituary.

The question is how and where you expect a person buying flowers to indicate which obituary they are for.

Is the user browsing a WooCommerce shop and adding flowers to the cart, then completing the WooCommerce workflow to place the order and pay for it online? Where in this process is the obituary specified, because the actual connection between flower product and obituary would be made when the order is completed, and the challenge is knowing what obituary the flowers belong to at that point.

#1124283

The question is how and where you expect a person buying flowers to indicate which obituary they are for.
---Answer for above question is when user click on Obituary Detail. I have created one tab for flower shop in which I am displaying all the products using View and Post Form.

Is the user browsing a WooCommerce shop and adding flowers to the cart, then completing the WooCommerce workflow to place the order and pay for it online?
Yes user will add flower in cart and will pay online using paypal or credit card.
Where in this process is the obituary specified, because the actual connection between flower product and obituary would be made when the order is completed, and the challenge is knowing what obituary the flowers belong to at that point.
-------- I don't know answer of the above question and I seeking help regarding that.
----------It would be great if you can help me for this because I am stuck here and can't able to get any soultion

#1124638

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Henry

OK, thanks for clarifying, you are not using the WC shop page, but starting from the Obituary post, where you display flowers with Add-to-cart buttons.

Unfortunately, I cannot see any way to bridge the gap between the origin Obituary post and the checkout page so that the checkout page is aware of the origin Obituary post as you proceed via the cart. There may be a way to pass a variable along—as a URL parameter, for example—but you would need a WooCommerce expert to know if that were feasible.

In terms of achieving this with Toolset, you would need to effectively fake adding products to the cart and use the Toolset Forms Commerce workflow to publish some post and be charged for it.

The simplest version would be with a single form, where above the form you display a grid of flower products. Then the form itself includes a field where the user chooses the flowers they want to buy.

This field is then used to set which product is purchased when submitting the form.

If you create a many-to-many relationship between obituaries and products, the post which is published could be of an intermediate post type, for example, and you would use the API—possibly one of the Forms Commerce hooks such as cred_commerce_form_action—to run a snippet of code that used toolset_connect_posts to connect the Obituary and the product.

I suggest you start by familiarising yourself with how Toolset Forms Commerce is used to pay to publish posts: https://toolset.com/documentation/user-guides/using-cred-commerce-to-add-payments-to-forms/

You can review the API documentation here:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_form_action
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts

If such a workflow seems feasible then try setting it up and see how far you get. I expect you would need help with using the APIs to connect the product and obituary, but let me know how far you get.