2

I am using JetAppoitment (crocoblock) to make services bookable. I would like to add the appoitment date to the orders from the front-end side.

Here is the code I used :

add_filter( 'woocommerce_account_orders_columns', 'add_account_orders_column', 10, 1 );
function add_account_orders_column( $columns ){
$columns['custom-column'] = __( 'Date de livraison', 'woocommerce' );

return $columns;
}

add_action( 'woocommerce_my_account_my_orders_column_custom-column', 
'add_account_orders_column_rows' );
function add_account_orders_column_rows( $order ) {
// Example with a custom field
if ( $value = $order->get_meta( '_appointment_date' ) ) {
    echo esc_html( $value );
}
}

The first part of the code worked good, the extra column is here : https://i.stack.imgur.com/kSLiq.png

The problem is I have no data...

Any idea to how to fix it?

Thanks

mujuonly
  • 11,370
  • 5
  • 45
  • 75
NasBEN
  • 59
  • 1
  • 8

1 Answers1

0
add_action('woocommerce_my_account_my_orders_column_custom-column',
        'add_account_orders_column_rows');

function add_account_orders_column_rows($order) {
// Example with a custom field
    if ($value = get_post_meta($order->get_id(), '_appointment_date')) {
        echo esc_html($value);
    }
}
mujuonly
  • 11,370
  • 5
  • 45
  • 75
  • Thanks for your reply, but it doens't work :( – NasBEN Mar 02 '22 at 12:51
  • Then confirm the meta key is correct, checking orders ids have the meta values in the database. – mujuonly Mar 02 '22 at 13:00
  • here is what I tried but it displays the order date. The error is at the end of the code ($data[0]['date']). Any idea about how to fix it ? `add_action( 'woocommerce_my_account_my_orders_column_order-date', 'add_order_date_orders_column_rows', 9999 ); function add_order_date_orders_column_rows( $order ) { if ( $value = get_post_meta($order->get_ID(), '_jet_apb_wc_details', true)['form_data']['appointment_date'] ) { $data = json_decode($value, true); echo esc_html( date('d/m/Y', $data[0]['date'] )); } }` – NasBEN Apr 08 '22 at 07:16
  • dump $data and check if it contains the expected result – mujuonly Apr 08 '22 at 07:17
  • already tried, it displays today's date – NasBEN Apr 08 '22 at 07:19