With WooCommerce I use the plugin WooCommerce Checkout add-on that add extra field to the checkout page.
I add a field named 'livraison' and it's saved id DB, but I can't get it with the code :
get_post_meta( $order->id, 'livraison', true );
I don't understand why is false...
What I am doing wrong?
Thank you
To solve your issue:
1) Checking in your database within
wp_postmetatable.You should make a search sticking this SQL search in SQL query window:
Because is possible that the
meta_keyslug of this custom field is for example'_livraison'.If you get nothing, you should check with another search for a defined order ID (for example below we search for order ID
1216):Then you will get all the meta data for this order and you will search visually for this custom field.
2) Making sure that you get an Order ID using **
$order->idwithget_post_meta()function.**Depending where you are using
get_post_meta()you need to be sure that$order->idisn'tnull.You should try to output before in your code
$order->idvalue for example with:If you don't get any order Id, here is the problem. In some WooCommerce hooks you can use for example
$order_idinstead, depending on the arguments of the hook used. Same thing for some templates.