WooCommerce show custom column

前端 未结 5 637
梦谈多话
梦谈多话 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:42

    To add new column coupon in woo-commerce order table and get all coupon code according to order. you need to copy and paste in you function.php.

    add_filter('manage_edit-shop_order_columns', 'custom_shop_order_column', 11);
    
    function custom_shop_order_column($columns) {
        //add columns
        $columns['my-column1'] = __('Coupons Code', 'theme_slug');
        return $columns;
    }
    
    // adding the data for each orders by column (example)
    add_action('manage_shop_order_posts_custom_column', 'cbsp_credit_details', 10, 2);
    
    function cbsp_credit_details($column) {
        global $post, $woocommerce, $the_order;
        $order_id = $the_order->id;
    
        switch ($column) {
            case 'my-column1' :
                // $myVarOne = wc_get_order_item_meta( $order_id, 15, true );
                if ($the_order->get_used_coupons()) {
    
                    $coupons_count = count($the_order->get_used_coupons());
                    foreach ($the_order->get_used_coupons() as $coupon) {
                        echo $coupon;
    
                        $i++;
                    }
    
                    echo '

    '; } // echo $myVarOne; break; } }

提交回复
热议问题