Skip Navigation

[Resolved] Cred Commerce from creating two orders and one of them as "guest"

This support ticket is created 7 years, 3 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
#556923
cred-commerce-form-settings.png

Something weird is going on.. the following used to work and I can't understand why it doesnt anymore..

Here is what I am trying to achieve:

1. User has a cpt "filialen" (locations)
2. Users sees a cred commerce form where he can select the parent "filiale" and have a product added to the cart.
3. He checks out and then in the "filialen" cpt there is a view showing order ids inside a link that takes him to that specific order in the my-account page.

This is what is happening right now when a user follows the steps outlined above:
1. Two orders are created
- One with all the correct order details, correct user but NOT assigned to any "filiale", even if I assign it afterwards from the bakend, it doesn't show in the view.
-One with basically no details at all (no user, no product, nothing) but correctly assigned to the "filiale" and shows inside the view correctly

Here is what I have tried:
Change all cred commerce form settings I could think of
show the view in different places
mess with the woocommerce settings to not allow guest checkout

Here is what I have already done:
Re-assign the oder posttype to be managed with types and make it a child of filialen

Attached is a screenshot of the credform settings and as they are, they did work before so that can't really be whats interfering. It didnt create two orders before and also never created them as a guest. "Bestellungen" ist the name of the order post type.

If you need access to a paypal sandbox account with which to place an order please enable private message 🙂

I have tried for hours now and just don't get why it ain't working anymore so any help would be highly appreciated. Thanks a lot in advance 🙂

#557023

Hi, is the CRED Commerce form ID #14? I just looked in your theme's functions.php files and found this code:

// Actions
add_action('cred_save_data', 'my_save_data_action',10,2);

// AUTOMATICALLY CREATE FIRMEN POST WHEN USER REGISTERS
add_action('cred_save_data', 'my_save_data_action',10,2);

You've registered this action callback twice...I wonder if this is the reason you're having two posts created. Please delete one of these and try again, and let me know the results.

#557952

Hey Christian

oh that must have been some leftover from messing around with various snippets 😉 Unfortunately it did not solve the issue, the form ID is 254 and its still create an order with all the correct data and a guest order :/

any other ideas? I haven't deleted the test account you made when helping me on another issue yet in case you wanna give it a try that way 😉

#557965

Okay this is a bit confusing. You have a custom post type "Bestellungen" created in Types:
hidden link

The CRED Commerce form is set up to create posts of the "Bestellungen" post type:
hidden link

WooCommerce expects to use the shop_order slug for its own orders, but your custom post type already uses that slug. So I think this is why things are acting strangely. CRED Commerce forms should not create Orders, they should create some other post type. The WooCommerce Order is not actually created by CRED Commerce, it is created when your visitors checkout using your WC checkout form. The "Bestellungen" post type should not be created by Types, it should be managed by WooCommerce.

My guess is that you already created that Bestellungen post type in Types before you installed WooCommerce. I'm not sure what the best way is to revert what you've got now, but I recommend deleting the custom post type Bestellungen you created in Types. Then I think WooCommerce Orders should begin displaying in the WooCommerce admin area instead of in your custom post type.

Here's a link to some CRED Commerce information:
https://toolset.com/documentation/user-guides/using-cred-commerce-to-add-payments-to-forms/

#558889

Ok I am a little confused now hehe

I had a thread to originally create this functionality here: https://toolset.com/forums/topic/show-product-id-with-link-of-bought-product-in-cpt-with-cred-commerce-form/

Here I had to manage the orders using types so now I am not sure which way is the best to go in order to show the orders (as a child to a cpt) in a list with a link in those cpts..

#559315

Okay I see, you have some custom functionality here that I was not fully aware of. You can disregard my information about deleting the custom post type for Orders. My other instruction remains the same - your CRED Commerce form should not create Orders. It should create a different post type, probably something you create in Types specifically for this purpose.

When the Order is completed, the cred_commerce_after_order_completed hook is fired:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed

You can use this hook to do something like set the parent CPT of the related Order (provided in the callback as transaction_id). Then the Order would display in a View of child Orders of the parent CPT.

Let me know if you need assistance here.

#559422

Yes I would really appreciate your assistance on this. Could elaborate a little on the hook? Maybe some sample code that I can work off?

So first I create a new cpt lets say "my-custom-orders". Cred Commerce form will create a new post of this cpt on submission and the hook will fire setting things like the parent of the order.

In my view I can select the order ID's and put a link on it as I did previously and that should be about it correct?

And the current order cpt managed by types should stay as is?

Thanks for everything! 🙂

#559555

Your explanation sounds right, so I think we understand each other. The link I posted earlier contains the details about this API method and the data you can expect to receive:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed
The example shown there doesn't really help much. Here's an extended example:

add_action( 'cred_commerce_after_order_completed', 'set_parent_filialen_hook', 10, 1 );
function set_parent_filialen_hook( $data ) {
  $order_id = $data['transaction_id'];
  $parent_id = 12345;
  update_post_meta($order_id, '_wpcf_belongs_filialen_id', $parent_id);
}

So the idea is that you capture the order ID from the data object. Then you need to figure out which filialen post should be the parent of this order. For now, let's hard-code it for testing purposes. Just replace 12345 with the numeric ID of a Filialen post you want to use as the parent. Then you update the Order's postmeta information and add a meta value that defines the parent Filialen for types using the key '_wpcf_belongs_slug_id'. You must modify the '_wpcf_belongs_filialen_id' string to match your filialen post type slug, if it is not "filialen".

Try this out and confirm it is adding the hard-coded parent to the Order once the Order is completed. Then we can work on figuring out the parent ID.