Skip Navigation

[Resuelto] Follow up to «Membership to allow access to front-end editing of specific posts»

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

I am using Toolset form and CRED commerce plugins, if the customer fails to complete checkout, instead of changing the post status to "Pending" or "Draft" it just changes the free-premium field to free?

Solution:

I suggest you try this:

1) In your CRED form, but don't display "free-premium" field, so when user submit the CRED form, it won't change the value of "free-premium" field.

2) After the users submit the CRED form and complete the Woocommerce order, use the CRED commerce action hook "cred_commerce_after_order_completed" to trigger a custom PHP function, in this function, update the "free-premium" field to what you want.

See the codes provided by client:

https://toolset.com/forums/topic/follow-up-to-membership-to-allow-access-to-front-end-editing-of-specific-posts/#post-877275

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed

Action to be executed after WooCommerce order status is set to completed.

This support ticket is created hace 6 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: 

Este tema contiene 3 respuestas, tiene 2 mensajes.

Última actualización por Luo Yang hace 6 años, 6 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#872980

Hi Nigel

This is a follow up to my last support ticket - I added another comment on there but not sure if you will get notifications about it now.

I've got a good way down the road with doing this now but have a specific problem with the way I'm doing something. Perhaps you can help me do what I want, or give me a nudge towards a different way to achieve what I'm trying...

So as it stands a user can create an account and log in (to a new user role called CPT owner).
Once they are logged in they can see the Claim form and submit it for admin approval.
Once approved the admin sets the user as the post author.
Now that they're the post author they can see the edit post form that allows them to update the post.

All well and good....

The next part is having premium fields. I have a field called "free-premium", and certain other fields are only visible/editable if this is set to premium. This part works OK.

The difficulty is getting the user to purchase the "premium listing" so that the filed is set to premium and the fields editable.
As it stands I have a simple cred form - it looks like this:

[credform class='cred-form cred-keep-original']
[cred_field field='form_messages' value='' class='alert alert-warning']
<div class="form-group" style="display:none;">
  [cred_field field='free-premium' post='tool' value='premium' urlparam='' output='bootstrap']
</div>
[cred_field field='form_submit' value='Upgrade to Premium' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
[/credform]

So the form has the free-premium field set to premium, but this is hidden by the display:none. The user just has to submit the form. The form is linked via "Charge payment with this form" to a Woocommerce product and is directed immediately to the checkout page.

In theory this works OK as long as they pay, but if they don't complete payment, the form has already been submitted and recorded the "free-premium" field as premium.

I see I can change "Post status when the payment status updates", but I don't want to change a post to "Pending Review" as then Guest visitors won't be able to see the post - I'd still want them to see the post, just not the premium info.

So is there any way I can do this with the cred form - i.e. if the customer fails to complete checkout, instead of changing the post status to "Pending" or "Draft" it just changes the free-premium field to free?

If not, how should I restructure this bit of the process to allow users to purchase premium in this way?

Sorry for the long post. If you need log in details to see what I'm talking about on the staging site let me know.

Thanks
Tim

#874995

Dear Tim,

Nigel isn't available, I will take care of this thread.

For your question:
if the customer fails to complete checkout ... it just changes the free-premium field to free?
I suggest you try this:
1) In your CRED form, but don't display "free-premium" field, so when user submit the CRED form, it won't change the value of "free-premium" field.

2) After the users submit the CRED form andcomplete the Woocommerce order, use the CRED commerce action hook "cred_commerce_after_order_completed" to trigger a custom PHP function, in this function, update the "free-premium" field to what you want. see our document:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed
Action to be executed after WooCommerce order status is set to completed.

#877275

Thanks. Exactly what I needed.

For completeness here's the code changes:
The forms are as follows:

Form with id=898

  [credform class='cred-form cred-keep-original']
  [cred_field field='form_messages' value='' class='alert alert-warning']
  [cred_field field='form_submit' value='Upgrade to Featured' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
  [/credform]

Form with id=900

  [credform class='cred-form cred-keep-original']
  [cred_field field='form_messages' value='' class='alert alert-warning']
  [cred_field field='form_submit' value='Upgrade to Premium' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
  [/credform]

This was added to child theme functions.php.

/* After Order completes, update to Premium or Featured */
add_action('cred_commerce_after_order_completed','set_post_upgrade',10,1);
function set_post_upgrade($data)
{
    $cred_form_id = $data['extra_data'][0]['cred_form_id'];
    if ($cred_form_id == 900) {
        $cred_post_id = $data['extra_data'][0]['cred_post_id'];
        $res = update_post_meta($cred_post_id, 'wpcf-free-premium', 'premium');
    }
    if ($cred_form_id == 898) {
        $cred_post_id = $data['extra_data'][0]['cred_post_id'];
        $res = update_post_meta($cred_post_id, 'wpcf-featured', '1');
    }
}
#881804

Thanks for sharing the codes, that will help other users.