最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Strange issue saving custom field data for a WooCommerce order

programmeradmin3浏览0评论

I have an issue with WordPress update_post_meta() function. So I have made a custom input field for WooCommerce orders which hold Tracking number. Most of the time everything is running smooth and I am able to add and update this number. However on some rare occasions I find that the tracking number is not saved for the order which is open, but rather is saved for another order.

What I mean by that. For example if my $item_id is 2000, after the update has finished, I see in the logs or database that completely different ID has been updated (e.g. 1986). Here is the example code:

$item_tracking_nr_data = 'EU373655223'
update_post_meta( $item_id, '_custom_print_providers_item_tracking_nr', $item_tracking_nr_data );

What I have tried:

  1. Deactivating all plugins
  2. Switching to default WordPress theme
  3. Manually setting the $item_id = 2000 and saving the tracking number

I also tried hoking into custom field update process to see what goes on inside there to learn that yes, before and after the saving process the ID is indeed 2000, however during the saving process inside the function the value somehow has changed to 1986.

Here is the test I did to learn that the

function test_meta_data($check, $item_id, $meta_key, $meta_value, $unique) {
    var_dump( $item_id ); //This returns 1986 during the test
}

add_filter('add_post_metadata', 'test_meta_data', 20, 5);
add_filter('update_post_metadata', 'test_meta_data', 20, 5);

Maybe somebody has had something similar or notices if I'm doing something the wrong way?

发布评论

评论列表(0)

  1. 暂无评论