• Resolved delvitavb

    (@delvitavb)


    Hello,

    I use the following code to add the contents of some custom checkout fields to my invoices and packing slips:

    function custom_order_info_fields( $fields, $order ) {
    
    	$custom_fields = array(
            array(
                'label' => 'Vergi Dairesi:',
    	    'value' => get_post_meta( $order->get_id(), '_billing_vergidairesi', true ),
            ),
            array(
                'label' => 'T.C./Vergi No:',
    			'value' => get_post_meta( $order->get_id(), '_billing_tckimlik_vergino', true ),
            ),
        );
    
        $fields = array_merge( $fields, $custom_fields );
        return $fields;
    }
    
    add_filter( 'wcdn_order_info_fields', 'custom_order_info_fields', 10, 2 );

    The code works as intended except it gives empty values for the custom fields. There are no errors in debug logs, and when I dump some variables with:

    var_dump(get_post_meta( $order->get_id(), '', false ));

    I see the get_post_meta() returns data from my db table wp_postmeta instead of wp_wc_orders_meta where the custom fields are stored. wp_postmeta does have entries for every orderID that has a successful payment, because my payment gateway plugin stores them there, I’m not sure how or why.

    Why does this happen and how do I make get_post_meta() return custom checkout fields?

    Everything else seems to work fine. Below is my related config:

    • WordPress 6.4.3
    • WooCommerce 8.5.2
    • Checkout Field Editor for WooCommerce 2.0.0
    • Raft 1.1.1 (theme)
    • Code Snippets 3.6.2
    • Print Invoice & Delivery Notes for WooCommerce 4.8.1

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Hey there, @delvitavb! Thanks for contacting us.

    While we can’t provide support for code customization as per our support policy, we do our best to offer advice and direct you to appropriate resources.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there too.

    I’m going to leave it open for a bit to see if anyone is able to chime in and help you out further.

    Have a wonderful day!

Viewing 1 replies (of 1 total)
  • The topic ‘get_post_meta() gets data from db table wp_postmeta instead of wp_wc_orders_meta’ is closed to new replies.