Problem: I would like to set the value of a custom field automatically whenever a WooCommerce Order is created from the front-end of the site.
Solution: Use a custom code snippet with the save_post hook to programmatically set the custom field value:
function tssupp_set_select_value_1 ( $post_id, $post, $update ) { $field_slug = 'custom-field-slug'; $forced_value = '1'; $post_type_slug = 'shop_order'; // you should not edit anything below this line // - bail on wrong post type or on update $post_type = get_post_type( $post_id ); if ( $post_type !== $post_type_slug || $update ) { return; } update_post_meta( $post_id, 'wpcf-' . $field_slug, $forced_value ); } // 1688213: Automatically select custom field value when order is created add_action( 'save_post', 'tssupp_set_select_value_1', 100, 3);
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)
This topic contains 2 replies, has 2 voices.
Last updated by 4 years, 5 months ago.
Assisted by: Christian Cox.