0

我正在尝试创建一个简码以在 Woocommerce 中显示订单详细信息,但是当我保存 functions.php 文件时它向我显示错误:

由于文件 Unknown 的第 0 行出现错误,您的 PHP 代码更改已回滚。请修复并再次尝试保存。

在没有堆栈帧的情况下抛出异常

代码部分来自从 WooCommerce 3 中的订单项中获取一组特定数据

  add_shortcode( 'custom-woocommerce-order-details' , 'custom_order_details' );
    function custom_order_details(){
        
    $order_items = $order->get_items(); // Get order items array of objects
    $items_count = count($items); // Get order items count
    $items_data  = []; // Initializing
    
    // Loop through order items
    foreach ( $order_items as $item_id => $item ) {
        $variation_id = item->get_variation_id();
        $product_id   = $variation_id > 0 ? $variation_id : $item->get_product_id();
    
        // Set specific data for each item in the array
        $items_data[] = array(
            'id'          => $product_id,
            'description' => $item->get_name(),
            'quantity'    => $item->get_quantity(),
            'value'       => $item->get_subtotal(),
            'salesTax'    => $item->get_subtotal_tax(),
        );
    }
        $output = array(
        'firstName'       => $order->get_billing_first_name(),
        'lastName'        => $order->get_billing_last_name(),
        'mobilePhone'     => $order->get_billing_phone(),
        'email'           => $order->get_billing_email(),
        'address'         => array(
            'street'          => $order->get_billing_address_1(),
            'suiteApartment'  => $order->get_billing_address_2(),
            'city'            => $order->get_billing_city(),
        ),
        'products'        => $items_data, // <=== HERE
    );
        
        return $output;
    }
4

0 回答 0