Skip Navigation

[Resolved] get post id created by cred commerce

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to get the ID of the post created by a Form that uses Forms Commerce.

Solution: Use the cred_commerce_after_payment_completed API to access the order number:

add_action('cred_commerce_after_payment_completed','add_order_number',10,1);
    function add_order_number($data) {
        $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
}

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/

0% of people find this useful.

This support ticket is created 6 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

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

Author
Posts
#1101733

Hello Christian,

The Cart can include product related to Booking OR Pack which means I'll add 2 views (1 for each CPT) with same filters that you advised

and as the customer can purchase a pack, so both views will display results.

from the frontend I can't get the id of the product in the cart so I can set conditional based on the product category so I could display the right view and hide the other.

the direct way to achieve that is if I have the id of that newly created Booking / Pack so I can have only 1 view for both CPTs with a post ID filter

I hope I explained it clearly now. Thank you so much for you patience 🙂

New threads created by Christian Cox and linked to this one are listed below:

https://toolset.com/forums/topic/conditional-based-on-product-category-of-item-in-cart/

#1101781

Okay I've split that request off into a separate ticket. Let's keep this ticket focused on adding the correct product to the cart and updating the quantity calculations based on the number of days selected. We were able to accomplish that with the CRED Commerce API, but the getting the post ID on the Cart page is quite a different task.

#1102642

Hello Christian,

I followed your advise and created one view for both CPTs