WooCommerce show custom column

前端 未结 5 635
梦谈多话
梦谈多话 2020-12-01 06:45

I want to show a additional column in the backend of WooCommerce (in Orders overview). The column should contain a custom field, which i have defined (delivery date).

<
5条回答
  •  臣服心动
    2020-12-01 07:25

    The following works for WooCommerce 2.6.2. You should look into two new hooks:

    • woocommerce_admin_order_item_headers, invoked once when orders table header is generated
    • woocommerce_admin_order_item_values, invoked once per every item inside the order

    1. Define columns headers

    add_filter('woocommerce_admin_order_item_headers', 'so13683162_headers');
    function so13683162_headers($order) {
        echo "FIELD1";
    }
    

    2. Populate values in rows

    add_filter('woocommerce_admin_order_item_values', 'so13683162_values');
    function so13683162_values($product) {
        if (isset($product -> id)) {
            $attrs = get_post_meta($product -> id, "_product_attributes", true);
            echo "" . $attrs["FIELD1"]["value"] . "";
        }
    }
    

提交回复
热议问题