Woocommerce получает выбранный вариант из объекта заказа - PullRequest
0 голосов
/ 02 июля 2019

Я пытаюсь получить варианты от объекта заказа.Это мой код:

// This is my order object.
global $order;

// I am getting items from order.
$items = $order->get_items();

// Get single item from items
foreach( $items as $item ) {
    // Get product id which i bought.
    $product_id = $item->get_product_id();

    // Get product object which i bought
    $product = wc_get_product( $product_id );

    // This is my problem! It gets all variations. I want to gent only selected when customer was buying.
    $product_variation_name = $product->get_attribute( 'my-custom-variation' );
}

Как я уже сказал.Я пытаюсь получить выбранный вариант из моего заказа на покупку.Но $product->get_attribute получает все варианты.

На странице продукта мой вариант выглядит следующим образом:

<select name="variation" id="variation">
    <option value="pa_my-custom-variation">My Custom Variation</option>
    <option value="pa_other-variation">Other Variation</option>
    <option value="pa_other-variation-1">Other Variation 1</option>
</select>
...