I am working on a small plugin for WooCommerce that will allow me to create a URL from an object to link to a certain page. That page will take into account the PHP GET variables and generate a technical drawing. In my theme’s “admin-new-order.php” page, I have added the following code just above where the email’s order table is generated:

$ordered_items = $order->get_items();
foreach ( $ordered_items as $item ) {
$product_name = $item['name'];
    $product_id = $item['product_id'];
    $product_variation_id = $item['variation_id'];

    if($product_id == "1388")
    {
        if ($product_variation_id) { 
        $product = new WC_Product($item['variation_id']);
        echo "NAME: ";
        echo $product->get_attributes();
        // Get the attributes
        // Process the attributes
        // Create URL 
        // Echo URL
        }
    }

}

If I put an echo into the above then it appears in the right place of the email, so I know the code is executing as expected.

The links will be generated only by product with id “1388”, which also executes as expected in testing. Product id “1388” is a variable product where the customer can select material, shape etc. and also I am using the Measurement Price Calculator plugin so the user can set their required size.

The problem lies within the line that says

echo $product->get_attributes();

When this line of code is present, I get an internal server error when trying to make an order and the order won’t go through.

I am trying to get the selected attributes from out of the product so I can splice them up and generate a URL to take you to a page that will generate a technical drawing. I know it’s possible because the table in the email contains the set attributes but I can’t seem to find where and how WooCommerce does this.

A push in the right direction would be greatly appreciated, thank you.

Read more here: Get WooCommerce product attributes from complete order?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: