logo
down
shadow

Woocommerce display custom field data on admin order details


Woocommerce display custom field data on admin order details

By : Tracy A Sutton
Date : November 16 2020, 03:01 PM
I wish this help you As you are saving this custom field data, using the meta_key: 'Business Address?'… So you need to use this meta_key to retrieve the data this way:
code :
// Display field value on the admin order edit page
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'custom_checkout_field_display_admin_order_meta', 10, 1 );
function custom_checkout_field_display_admin_order_meta( $order ){
    $business_address = get_post_meta( $order->get_id(), 'Business Address?', true );
    if( ! empty( $business_address ) )
        echo '<p><strong>'.__('Ship to a Business Address', 'woocommerce').': </strong> ' . $business_address . '</p>';
}


Share : facebook icon twitter icon
Woocommerce Admin Order Details - Show custom data on order details page

Woocommerce Admin Order Details - Show custom data on order details page


By : vickriliayulia
Date : March 29 2020, 07:55 AM
like below fixes the issue Here's a start on how to display some extra data on the woocommerce_before_order_itemmeta hook:
code :
add_action( 'woocommerce_before_order_itemmeta', 'so_32457241_before_order_itemmeta', 10, 3 );
function so_32457241_before_order_itemmeta( $item_id, $item, $_product ){
    echo '<p>bacon</p>';
}
add_filter( 'get_post_metadata', 'so_32457241_order_thumbnail', 10, 4 );
function so_32457241_order_thumbnail( $value, $post_id, $meta_key, $single ) {
    // We want to pass the actual _thumbnail_id into the filter, so requires recursion
    static $is_recursing = false;
    // Only filter if we're not recursing and if it is a post thumbnail ID
    if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) {
        $is_recursing = true; // prevent this conditional when get_post_thumbnail_id() is called
        $value = get_post_thumbnail_id( $post_id );
        $is_recursing = false;
        $value = apply_filters( 'post_thumbnail_id', $value, $post_id ); // yay!
        if ( ! $single ) {
            $value = array( $value );
        }
    }
    return $value;
}


add_filter( 'post_thumbnail_id', 'so_custom_order_item_thumbnail', 10, 2 );
function so_custom_order_item_thumbnail( $id, $post_id ){
    if( is_admin() ){
        $screen = get_current_screen();
        if( $screen->base == 'post' && $screen->post_type == 'shop_order' ){
            // this gets you the shop_order $post object
            global $post; 

            // no really *good* way to check post item, but could possibly save 
            // some kind of array in the order meta
            $id = 68;
        } 
    }
    return $id;
}
Show Custom Data in Woocommerce Order Details Admin Area

Show Custom Data in Woocommerce Order Details Admin Area


By : Lingualancer
Date : March 29 2020, 07:55 AM
This might help you May be i am displaying data in wrong place in your order detail page. But you can check there is multipe hook avilable for this woocommerce/inculdes/admin/meta-boxes-/view/html-order-items.php.
I just take one this hook. Please add this code in functions.php
code :
function my_function_meta_deta() {
    echo "I am here";
}
 add_action( 'woocommerce_admin_order_totals_after_refunded','my_function_meta_deta', $order->id );
Display custom checkout field value on admin order detail section in Woocommerce

Display custom checkout field value on admin order detail section in Woocommerce


By : user1709720
Date : March 29 2020, 07:55 AM
like below fixes the issue There is some mistakes, so I have revisited your code. I have also replaced some hooks. Try the following:
code :
// HERE set your the options array for your select field.
function delivery_time_options(){
    $domain = 'woocommerce';
    return array(
        '1' => __('10:04 : 13:04 ', $domain),
        '2' => __('14:04 : 16:04 ', $domain), // <== Added for testing
    );
}

// Display a custom select field after shipping total line
add_action( 'woocommerce_review_order_after_shipping', 'checkout_shipping_additional_field', 20 );
function checkout_shipping_additional_field(){
    $domain = 'woocommerce';

    echo '<tr class="additional-shipping-fields"><th>' . __('Delivery Time', $domain) . '</th><td>';

    // Add a custom select field
    woocommerce_form_field( 'delivery_time', array(
        'type' => 'select',
        'class' => array( 'form-row-wide' ),
        'options' => delivery_time_options(),
    ), '' );

    echo '</td></tr>';
}

// Save custom field as order meta data
add_action('woocommerce_checkout_create_order', 'save_custom_field_order_meta', 22, 2 );
function save_custom_field_order_meta( $order, $data ) {
    if ( isset($_POST['delivery_time']) ) {
        $options    = delivery_time_options(); // Get select options array
        $option_key = esc_attr($_POST['delivery_time']); // The selected key

        $order->update_meta_data( '_delivery_time', $options[$option_key] ); // Save
    }
}

// Display a custom field value on the admin order edit page
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'display_custom_meta_data_in_backend_orders', 10, 1 );
function display_custom_meta_data_in_backend_orders( $order ){
    $domain = 'woocommerce';

    $delivery_time = $order->get_meta('_delivery_time');
    if( ! empty( $delivery_time ) )
        echo '<p><strong>'.__('Delivery Time', $domain).': </strong> ' . $delivery_time . '</p>';
}
Display checkout field value in Woocommerce admin order list custom column

Display checkout field value in Woocommerce admin order list custom column


By : user2077875
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The following revisited code will add a custom column and will display the custom checkout field "Enclosed Invoice" value:
code :
// Add custom checkbox field to checkout
add_action( 'woocommerce_review_order_before_submit', 'my_custom_checkout_field' );

function my_custom_checkout_field() {
    echo '<div id="my_custom_checkout_field">';

    woocommerce_form_field( '_enclosed_invoice', array(
        'type'      => 'checkbox',
        'class'     => array('input-checkbox'),
        'label'     => __('Enclose invoice? (Otherwise only delivery note)'),
    ),  WC()->checkout->get_value( '_enclosed_invoice' ) );

    echo '</div>';
}

// Save the custom checkout field in the order meta, when checkbox has been checked
add_action( 'woocommerce_checkout_create_order', 'save_order_custom_meta_data', 10, 2 );
function save_order_custom_meta_data( $order, $data ) {
    if ( isset($_POST['_enclosed_invoice']) )
        $order->update_meta_data('_enclosed_invoice', '1' );
}

// Display the custom field result on the order edit page (backend) when checkbox has been checked
add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_custom_field_on_order_edit_pages', 10, 1 );
function display_custom_field_on_order_edit_pages( $order ){
    if( $my_field_name = $order->get_meta( '_enclosed_invoice' ) )
        echo '<p style="background: #dba029; padding: 1em !important; color: #fff; font-weight: 700;"><strong>Enclosed invoice!</strong></p>';
}

// Add custom column before "Actions" column in admin orders list
add_filter('manage_edit-shop_order_columns', 'add_enclosed_invoice_order_column', 10, 1 );
function add_enclosed_invoice_order_column( $columns ) {
    // Woocommerce compatibility since version 3.3
    $actions_key = isset($columns['wc_actions']) ? 'wc_actions' : 'order_actions';

    $order_actions = $columns[$actions_key];

    unset($columns[$actions_key]);

    $columns['enclosed_invoice'] = __("Enc. Invoice", "woocommerce");

    $columns[$actions_key] = $order_actions;

    return $columns;
}

// Display data to custom column in admin orders list
add_action( 'manage_shop_order_posts_custom_column' , 'display_enclosed_invoice_order_column_data' );
function display_enclosed_invoice_order_column_data( $column ) {
    global $the_order, $post;

    if( $column  == 'enclosed_invoice' ) {
        if( $enclosed_invoice = $the_order->get_meta( '_enclosed_invoice' ) ) {
            echo __("Yes", "woocommerce");
        } else {
            echo ' - ';
        }
    }
}
How to add custom field and display it in admin-new-order.php file in woocommerce?

How to add custom field and display it in admin-new-order.php file in woocommerce?


By : yhwang
Date : March 29 2020, 07:55 AM
This might help you Well i think a new user field should have been added to wp_usermeta table instead of the wp_users table. The way you are looking with get_currentuserinfo(); this means that it is added to the users table. But if it was added to the usermeta table then you should have done this.
Related Posts Related Posts :
  • How to add new Custom Title in Woocommerce My Account sidebar?
  • Mattermost, slash command response as message attachment
  • Library failure when installing Libsodium (Amazon EC2)
  • Page footer centering using MPDF
  • HTML : Different link at each click
  • TCPDF how to prevent page break within a block (split content)?
  • How to insert values in table
  • Php query builder for OR and AND condition
  • ZF2 Ajax call returns all information instead of just the id being sent
  • Order custom post types in WordPress by the meta_value of another plugin
  • saving bank row using array
  • Convert URL with query parameters to guzzle
  • Get POST values by index in codeigniter
  • Composer is not functioning?
  • Retrieving an Array with Axios in Laravel
  • How to get the last child of each cd element?
  • How to allow users to connect their own domain
  • PHP multidimensionnal array and empty value
  • PHP if statement doesn't work properly (paradoxical)
  • BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::searchable()
  • PHP explode() returns array inside an array
  • Echo parse error for creating new php file
  • PHP Parse error: syntax error, unexpected '?'
  • PHP Session not working correctly on a particular host
  • laravel how to get the extremities tables through the pivot
  • Show duplicate value in array only one but show all others
  • SMTP Emails not send (There is something wrong with server config as code is fine for other servers)
  • I can't turn off debug bar in Laravel on production
  • PHP creating multidimensional json
  • Increment value with get
  • Laravel 5.5: Convert query builder to eloquent
  • Reverse proxy onto a WordPress page?
  • Jumble Solver url rewrite
  • Using .htaccess to Execute php if directory of the same name not found
  • mysql - Unknown Column In Where Clause
  • Receive Emails into my Admin panel with php or other
  • PHP - adding only distinct value to an array in foreach loop not working
  • How to pass date picker from one page to another
  • Try catch always return error when I insert 2 data
  • Php redirect not working on submission
  • How to get array value from wordpress database get_results
  • how Automatically go from first.php to second.php
  • uploading file not working in codeigniter 3 error: you did not select any file
  • Yii2, gridview can not show some html tags inside cells
  • What are the thing we need to configure to implement live notification module (using redis and socket.io) in https serve
  • How to handle multi criterias search in PHP
  • PHP - Get maximum key and its value in array
  • PHP: how to retrieve all the metrics and dimensions from the Google Metadata API?
  • Deliver php mails to special-character-email adresses, such as äüö
  • Delete a single row from an MSSQL table from PHP
  • Property [name] does not exist on this collection instance
  • Pass input value through PHP parameter
  • Running two PHP versions on the same server (STRETCH)
  • Checking if a file has been selected for upload
  • Model not updating laravel
  • How to add a description of words from text to an array, to an array key by passing words?
  • Nginx rewrite rule not not passing variables if "/" is at the end of the url
  • Modify decimal point and thousands separator without changing the number of decimals
  • Remove PHP errors from CLI and PHPMyAdmin
  • Yii2 rest api - Url manager add parameters
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org