Skip Navigation

[Resolved] Trying to programmatically change a field value

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 – 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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by jamesA-6 1 year, 8 months ago.

Assisted by: Waqar.

Author
Posts
#2441629

Tell us what you are trying to do?
On checkout of a certain product type (tied to Toolset Commerce) I want to change the value of the Payment Status toolset custom field.

Is there any documentation that you are following?
I have this function in place and I wonder if it immediately obvious why my field value is not being changed?

function payment_complete( $order_id, $old_status, $new_status ){
if( $new_status == "completed" ) {

$user_id = get_current_user_id();

$args=array(
'post_type' => 'song-contest-entry',
'post_status' => 'publish',
'posts_per_page' => 1,
'author' => $user_id
);

$current_user_posts = new WP_Query ( $args );

//LOOP START
if ( $current_user_posts->have_posts() ) {

while ( $current_user_posts->have_posts() ) { $current_user_posts->the_post();

$payment_status = get_post_meta(get_the_ID(), 'wpcf-paymentstatus', true);

if ($payment_status == 'Unpaid') {

update_post_meta( $post_id, 'wpcf-paymentstatus', 'Paid' );

}

}
}

//LOOP END

}
}

add_action( 'woocommerce_order_status_changed', 'payment_complete', 99, 3 );

Is there a similar example that we can see?
Not that I am aware of.

What is the link to your site?

#2442323

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

The steps and the logic used in your custom function seem correct.

If the custom field value is not updated when the order status is changed to 'completed', I recommend performing line-by-line debugging to see which part of the code is working and which isn't.

You'll find some useful information on using the debugging error log for such troubleshooting:
https://stackoverflow.com/a/55515556

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2442881

My issue is resolved now. Thank you!

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