在WooCommerce管理员订单列表中显示每个订单的变体名称

时间:2020-05-08 04:00:03

标签: php wordpress woocommerce backend orders

我很难在每个订单的管理订单列表中显示版本名称。

我尝试了这段代码,但它给了我一个错误:

// Get an instance of the WC_Order object from an Order ID
$order = wc_get_order( $order_id ); 

// Loop though order "line items"
foreach( $order->get_items() as $item_id => $item_product ){
    $product_id = $item_product->get_product_id(); //Get the product ID
    $quantity = $item_product->get_quantity(); //Get the product QTY
    $product_name = $item_product->get_name(); //Get the product NAME

    // Get an instance of the WC_Product object (can be a product variation  too)
    $product = $item_product->get_product();

    // Get the product description (works for product variation)
    $description = $product->get_description();

    // Only for product variation
    if($product->is_type('variation')){
        // Get the variation attributes
        $variation_attributes = $product->get_variation_attributes();

        // Loop through each selected attributes
        foreach($variation_attributes as $attribute_taxonomy => $term_slug){
            $taxonomy = str_replace('attribute_', '', $attribute_taxonomy );

            // The name of the attribute
            $attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;

            // The term name (or value) for this attribute
            $attribute_value = get_term_by( 'slug', $term_slug, $taxonomy )->name;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

要将变体添加到class ViewControllerA: UIViewController,ImageAssetsProtocol { override func viewWillAppear(_ animated: Bool) { var vc = ViewControllerC() vc.delegate = self } //This below method doesn’t get called func sendImageAssets(myData: [MyImageAsset]) { print(myData) } } ------------------------------------------------------------------------------------------ class ViewControllerC: UIViewController { protocol ImageAssetsProtocol { func sendImageAssets(myData: [MyImageAsset]) } weak var imagePreviewDelegate: ImagePreviewDelegate? //ViewControllerC gets an array of images from ViewcontrollerB. I’m passing that array to ViewControllerA override func viewWillDisappear(_ animated: Bool) { self.delegate?.sendImageAssets(myData: selectedAssets) } } 中,我创建了一个新列。

下面的代码没有错误,并且可以根据需要进行进一步的调整

admin order list