Skip Navigation

[Gelöst] Need connection between Custom Post and their Woocommerce Order/Subscription

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:

I am building a community website. I am selling individual posts for business listings, job posts, events listings, etc. Each post type is setup as a Types custom post type. Site members (subscribers) create these listings via Toolset Forms on the frontend and they complete their purchase with Woocommerce Subscriptions. Everything is working as planned except for one important factor... the Posts and the WooCommerce Orders/Subscriptions do not appear to be connected to each other.

Solution:

It is possible with some custom codes, see the solution here:

https://toolset.com/forums/topic/need-connection-between-custom-post-and-their-woocommerce-order-subscription/#post-1083572

Relevant Documentation:

This support ticket is created vor 6 Jahren, 2 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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: Asia/Hong_Kong (GMT+08:00)

Dieses Thema enthält 7 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Brent Urbanski vor 6 Jahren, 2 Monaten.

Assistiert von: Luo Yang.

Author
Artikel
#1081788

I am building a community website. I am selling individual posts for business listings, job posts, events listings, etc. Each post type is setup as a Types custom post type. Site members (subscribers) create these listings via Toolset Forms on the frontend and they complete their purchase with Woocommerce Subscriptions. Everything is working as planned except for one important factor... the Posts and the WooCommerce Orders/Subscriptions do not appear to be connected to each other.

I cannot figure out how to connect unique post(listing) to an purchase made with WooCommerce.

Me, as the business admin, needs to know which order/subscription belongs to which post.

My site members will need to see a list of their posts so they have they can extend or cancel their subscriptions, delete their posts, and view the subscription history.

I can't believe I'm unable to find instruction for this within Toolset's docs. Can you help?

Thanks,
Brent

#1082799

Dear Brent,

Q1) Me, as the business admin, needs to know which order/subscription belongs to which post.

You are right, there isn't such a built-in feature within Toolset form commerce plugin, if you agree, we can take it as a feature request.

Q2) My site members will need to see a list of their posts so they have they can extend or cancel their subscriptions, delete their posts, and view the subscription history.

In the Toolset form, there is a setting "Updating the post status when the payment status updates":
https://toolset.com/documentation/user-guides/using-cred-commerce-to-add-payments-to-forms/#3-1-updating-the-post-status-when-the-payment-status-updates

So your site members can cancel their order in woocommerce side
https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-4

after the user cancel the order, it will be able to update the post status, see screenshot
versteckter Link

And you can create a post view, filter by post author is current logged-in user, so site members will need to see a list of their posts
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

#1083145
Screen Shot 2018-08-14 at 11.29.42 AM.jpg

Hi Lou,

RE Q1) Me, as the business admin, needs to know which order/subscription belongs to which post.

You are right, there isn't such a built-in feature within Toolset form commerce plugin, if you agree, we can take it as a feature request.

Yes, please add this feature as I don't know how a business can sell and manage subscription listings without knowing which order/subscription was used to purchase which post. The post is the product being sold. Toolset market's itself as being capable of creating a classifieds or business directory websites, but I honestly don't know how one could manage the listings they are selling without this feature. Can you tell me how long this will take to implement? I'm planning to go live with my site within the next 4 to 6 weeks.

Q2) My site members will need to see a list of their posts so they have they can extend or cancel their subscriptions, delete their posts, and view the subscription history.

In the Toolset form, there is a setting "Updating the post status when the payment status updates":
https://toolset.com/documentation/user-guides/using-cred-commerce-to-add-payments-to-forms/#3-1-updating-the-post-status-when-the-payment-status-updates

I am aware of these form settings and I'm using them during the initial post purchase. There must be a permanent connection between the post and the WooCommerce order/subscription, right? How do we make this connection visible in the post, the WC order or subscription, or on a user's "my account" page?

So your site members can cancel their order in woocommerce side
https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-4

This would only work if the post titles were listed next to each order/subscription. Right now, the this WC page only shows the title of the product which is generically titled "Directory Listing", and not the actual post title it's linked to. Otherwise, how would a member know which post they were cancelling or extending the subscription of? Each member will likely have more than 1 post and order, so they need to know which post is tied to which subscription.


after the user cancel the order, it will be able to update the post status, see screenshot
versteckter Link

Again, we need to know which post is being cancelled.


And you can create a post view, filter by post author is current logged-in user, so site members will need to see a list of their posts
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/

I've already started a "my account" page for my members, but I need to be able to list WooCommerce details/links within this list. I've attached a mockup which includes a few buttons I'd like to add so members can delete their listing, renew the listing's subscription, view each listing's payment history, etc. Please let me know how I can achieve this with Views.

#1083572

There isn't any ETA for the feature request, currently, but there is a workaround, you can try to use action hook "cred_commerce_after_payment_completed" to save the post ID as a custom field of order post, and save the order ID as a custom field of post.

For example:
1) setup some custom fields:
- Create a custom field "my-post-id", and register it to post type "Order"
- Create a custom field "my-order-id", and register it to custom post type

2) When user complete the Woocommerce order, use action hook "cred_commerce_after_payment_completed" to trigger a custom PHP function
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_payment_completed

3) in this PHP function, save the post ID as a custom field "my-post-id" of order post, and save the order ID as a custom field "my-order-id" of post.
https://codex.wordpress.org/Function_Reference/update_post_meta

Then in a single order post, you will be able to get the related post ID by custom field "my-post-id",
in a single post, get the related order ID by field "my-order-id".

#1083904

I purchased Toolset because I am a non-coder and the instruction you provided is beyond my ability. Can you help me achieve the workarounds you mentioned, but in greater step-by-step detail? I don't know where I should register the custom fields for custom post types (within an individual post, within toolset custom fields groups, or with code?) How do I create these action hooks and where do I place them? Will registering the post-id allow me to get the post title(my members will understand post title but not post-id)?

#1084323

Please provide a test site with the same problem, I can setup a demo for you.

#1084427

Q1) I don't know where I should register the custom fields for custom post types (within an individual post, within toolset custom fields groups, or with code?)
You need to create two different post field group, each field group is for different post type:
https://toolset.com/documentation/user-guides/using-custom-fields/

Q2) How do I create these action hooks and where do I place them?
In most case, you can put the custom PHP codes into your theme file "functions.php".

Q3) Will registering the post-id allow me to get the post title(my members will understand post title but not post-id)?
With the post ID value, you can get the related post information easily, for example:
for example, the post ID is 123, you can display the post title with Views shortcode [wpv-post-title id="123"]
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-title

Q4) Can you describe in greater detail the workarounds you previously mentioned?
I have provided the detail steps here.
https://toolset.com/forums/topic/need-connection-between-custom-post-and-their-woocommerce-order-subscription/#post-1083572

Since it needs custom PHP codes, if you still need assistance for it, please provide a test site with the same problem, I can setup a demo for you.

#1087520

Hi Lou,

I was able to add WC Order ID to purchased Custom Posts, as well as add the purchased Post ID to WC Orders with the following code placed in my functions.php file.

Thank you for pointing me in the right direction. I still feel it's essential for Toolset to make improvements in the visibility/understanding of how these posts and orders are connected to each other. Honestly, I cannot believe more users have not reported this as a problem.

Please post the following code, or add how-to documentation to help other non-coders like me, and hopefully, Toolset will make this a built-in feature soon.

// Insert WooCommerce order number into purchased post's custom field
add_action('cred_commerce_after_payment_completed','add_order_number',10,1);
function add_order_number($data)
{
    // if a specific form
    $form_id = $data['extra_data'][0]['cred_form_id'];
    if ($form_id == 9876) 
    {   
        $order_number = $data['transaction_id']; //WooCommerce Order ID associated to the buying process
        $post_id = $data['extra_data'][0]['cred_post_id']; //Post ID that was created/edited with the form
        update_post_meta( $post_id, 'wpcf-my-dir-order-id', $order_number); //Add WooCommerce order number to purchased post's custom field
        update_post_meta( $order_number, 'wpcf-my-post-id', $post_id); //Add purchased post ID to WooCommerce order's custom field
    }
}

Thanks,
Brent