Output a product custom field in WooCommerce Order Admin Page (ACF)

前端 未结 1 876
滥情空心
滥情空心 2021-01-07 10:41

With WooCommerce, I\'m using the Advanced Custom Fields plugin to keep a track of where I physically store each product.

When an order comes in, I want to be able t

相关标签:
1条回答
  • 2021-01-07 11:05

    Updated: Using a custom function hoocked in woocommerce_before_order_itemmeta action hook, you will be able to achieve what you are looking for:

    add_action( 'woocommerce_before_order_itemmeta', 'storage_location_of_order_items', 10, 3 );
    function storage_location_of_order_items( $item_id, $item, $product ){
        // Only on backend order edit pages
        if( ! ( is_admin() && $item->is_type('line_item') ) ) return;
    
        // Get your ACF product value (replace the slug by yours below)
        if( $acf_value = get_field( 'BinLocation', $product->get_id() ) ) {
            $acf_label = __('Stored in: ');
    
            // Outputing the value of the "location storage" for this product item
            echo '<div class="wc-order-item-custom"><strong>' . $acf_value .  $acf_label . '</strong></div>';
        }
    }
    

    Code goes in any php file of your active child theme (or theme) or also in any plugin php file.

    This code is tested and works in WooCommerce version 3 and up…


    0 讨论(0)
提交回复
热议问题