Im trying to clean up some default database entries that WooCommerce adds to the postmeta table. The two primary entries that I do not need are _customers_ip_address
& _customer_user_agent
.
I found _customers_ip_address
in create_order()
function in file class-wc-checkout.php
do_action( 'woocommerce_checkout_create_order', $order, $data );
seems to be what is setting the data. Although I also found it was being set in wc-core-functions.php
@ function wc_create_order()
Im not 100% sure how to edit this. Im thinking a simple do_filter
, but unset
seems to not work inside the do_filter
, but obviously I am doing it all wrong. Im not that familiar with do_filter
but seems like something simple like the code below.
function cleanup_woocommerce_checkout_create_order($order, $data) {
unset($order->set_customer_ip_address());
return $order;
}
add_filter('woocommerce_checkout_create_order', 'cleanup_woocommerce_checkout_create_order');
The code above gives a WordPress Error of :
Fatal error: Can’t use method return value in write context
2
Answers
As I can see in this article, https://docs.woocommerce.com/wc-apidocs/source-class-WC_Checkout.html#397
so you should use add_action function
Or updating the post meta
or
First
woocommerce_checkout_create_order
is an action hook (but not a filter hook). Also you can not unset any method applied to an object as you are doing.What you can do is to try setting an empty value, like:
It should work.
If it doesn’t work, you can try to use
woocommerce_checkout_update_order_meta
action hook to remove this meta data afterwards once order data has been saved to database, this way:This last one should work anyways.