WC_REST_Paypal_Standard_Controller::get_variation_attributes_from_order_item
Get the variation attributes stored in an order item's meta, in the format expected by WC_Cart::add_to_cart(). This mirrors the attribute handling in WC_Cart_Session::populate_cart_from_order().
Метод класса: WC_REST_Paypal_Standard_Controller{}
Хуков нет.
Возвращает
array. Attribute values keyed by 'attribute_{name}'.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_variation_attributes_from_order_item( $item, $product_id ): array;
- $item(WC_Order_Item_Product) (обязательный)
- The order item.
- $product_id(int) (обязательный)
- The ID of the parent variable product.
Код WC_REST_Paypal_Standard_Controller::get_variation_attributes_from_order_item() WC REST Paypal Standard Controller::get variation attributes from order item WC 11.3.0
private function get_variation_attributes_from_order_item( WC_Order_Item_Product $item, int $product_id ): array {
$variation_attributes = array();
foreach ( $item->get_meta_data() as $meta ) {
$is_taxonomy_attribute = taxonomy_is_product_attribute( $meta->key );
if ( ! $is_taxonomy_attribute && ! meta_is_product_attribute( $meta->key, $meta->value, $product_id ) ) {
continue;
}
$attribute_key = 'attribute_' . sanitize_title( $meta->key );
if ( $is_taxonomy_attribute ) {
$variation_attributes[ $attribute_key ] = sanitize_title( $meta->value );
} else {
$meta_value = wc_clean( $meta->value );
$blog_charset = get_bloginfo( 'charset' );
if ( is_string( $meta_value ) ) {
$variation_attributes[ $attribute_key ] = html_entity_decode( $meta_value, ENT_QUOTES, $blog_charset );
} elseif ( is_array( $meta_value ) ) {
$variation_attributes[ $attribute_key ] = $this->decode_meta_values( $meta->value, $blog_charset );
}
}
}
return $variation_attributes;
}