0
votes

I am using Woocommerce for a site where there is just one payment method - credit card. However, we offer the customer different options,such as pay in full, pay in 4 payments, etc. All of that works fine - I store the # of payments in a session variable. I need to modify the payment method text (currently it just says "Via Credit Card") in the Admin order screen.

I tried this in

 if($_SESSION['payments'] == '4') add_post_meta( $order->id, '_payment_method_title', ' Via Credit Card with 4 Equal Payments');

But this didn't work. Session variable $_SESSION['payments'] is already cleared out at this point...the order is complete.

How can I modify the order meta data so that it shows in the order how many payments the customer wants? I create a solution using this code but it places the custom description with each item, not with the payment description for the order.

1

1 Answers

0
votes

To add custom meta to an order:

/**
 * Update the order meta with field value
 **/
add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
function my_custom_checkout_field_update_order_meta( $order_id ) {
    if ($_POST['my_custom_field']) update_post_meta( $order_id, '_my_custom_field', esc_attr($_POST['my_custom_field']));
}

(Credit goes to Woocommerce custom field not saving)

Then to add custom column and display the custom meta on the Woocommerce order screen:

//custom orders columns
add_filter( 'manage_edit-shop_order_columns', 'my_custom_order_columns',11 );
function my_custom_order_columns($columns) {
    $new_columns = (is_array($columns)) ? $columns : array();
    unset( $new_columns['order_actions'] );

    $new_columns['_my_custom_field'] = 'Custom Field';

    $new_columns['order_actions'] = $columns['order_actions'];
    return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'my_custom_columns_values', 2 );
function my_custom_columns_values($column){
    global $post;
    $data = get_post_meta( $post->ID );

    if ( $column == '_my_custom_field' ) {    
        echo (isset($data['_my_custom_field']) ? $data['_my_custom_field'][0] : '');
    }
}

(Credit goes to WooCommerce show custom column )