Skip Navigation

[Resolved] Submitting CRED form to create new CPT breaks permalinks, CPT archive and Search

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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 22 replies, has 2 voices.

Last updated by Shane 7 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#483000

Hi Shane,

Thank you for this code, it seems to be able to do just what I need.

But it does not work for me now, copy-pasting it leads to a whitescreen error. There must be a small issue, but I can't find this it in the code you suggest.

On the side - I was thinking: maybe it is better to use the (working) code to cred_commerce_after_order_completed ? That way the role is changed only after completing the whole process.

#483001

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jack,

I found the issue.

Try this new code and yes the woocommerce hook will work better .


add_action('cred_commerce_after_order_completed','my_hook',10,1);
function my_hook($data)
{
    // if a specific form
    if ($form_data['id']==12)
    {
   $current_user = wp_get_current_user();
       $user_arr = array( 'ID' => $current_user->ID, 'role' => 'my new role') ;
          wp_update_user( $user_arr);
         
    }
}
#485316

Hi Shane,

I did not get it to work yet, tried different things. I dived into the CRED commerce documentation at https://toolset.com/documentation/user-guides/cred-commerce-api/ and I think the cred_commerce_after_order_completed hook does not use the $current_user->ID variable, so that could be the reason?

I tried with user_id, but it doesn't work either. I don't see where this goes wrong, could you help?

#485493

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jack,

If you try this on your super admin account it may not work, you will need to try it on a test account.

Now the hook is just so that it will run when a certain criteria is met.

   $current_user = wp_get_current_user();

I'm actually getting the current user information with the line above so it should matter whether the function doesn't have it or not.

Could you try on a test role that you want to switch and let me know if it works.

Thanks,
Shane

#486975

Hi Shane,

I tried it completely logged out as a guest. It is not working.

The CRED form creates the CPT with the correct user, leads through Woocommerce for account creation and sends all the needed mails. So far so good... only the user role is not changing.

If you wish, you could use the login details I provided earlier to access the admin and test for yourself. If you need more details, or FTP Access, please open a private reply, so I can provide it.

The CRED form ID is #53
The role it is supposed to change to is 'zw*******er'

Thank you!

#487085

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jack,

I checked your functions.php file and noticed that function was not there,

Could you let me know where you added the code that I provided.

Thanks,
Shane

#487105

Hi Shane,

I have added it to the functions.php of the child theme. For some reason, this child theme was de-activated and the parent theme was activated (I think it happend after reinstalling the theme in an attempt to solve another issue I am having in another thread).

I activated the child theme again and tested the form - the code to update the user role it still is not working.

#487670

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jack,

I have some disappointing news 🙁

Wordpress doesn't allow users to edit their own roles, so it wouldn't be possible to change the role of the current user using the form.

The role will need to be changed manually by an admin.

Thanks,
Shane

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