0

I am trying to create a shortcode to display the order details in Woocommerce, but it shows me the error when I save the functions.php file:

Your PHP code changes were rolled back due to an error on line 0 of file Unknown. Please fix and try saving again.

Exception thrown without a stack frame

Code is partially from Get an array of specific data from order items in 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;
    }
cabral279
  • 97
  • 9

0 Answers0