John Davidson

php - Adding variable product attribute column in WooCommerce edit order page

0 comments
Message:


Based on Adding product attribute column to edit order page in Woocommerce answer code I wrote this function:


add_action( 'woocommerce_admin_order_item_headers', 'custom_admin_order_items_headers', 20, 1 );
function custom_admin_order_items_headers( $order ){

echo '<th>';
echo __('Marchio', 'woocommerce') . '</th>';
}

add_action('woocommerce_admin_order_item_values', 'my_woocommerce_admin_order_item_values', 10, 3);
function my_woocommerce_admin_order_item_values($_product, $item, $item_id = null) {

$marchio = get_the_terms( $_product->post->ID, 'pa_marchio');
echo '<td>' . $marchio[0]->name . '</td>';
}

It works for simple products but not with variable products, how can fix it?






My Answer:
Attribute';
}
add_action( 'woocommerce_admin_order_item_values', 'custom_admin_order_item_values', 20, 3 );
function custom_admin_order_item_values( $product, $item, $item_id ){
echo '';
$attributes = $product->get_attributes();
if ( $attributes ) {
foreach ( $attributes as $attribute ) {
echo '

' . $attribute['name'] . ': ' . $attribute['options'][0] . '

';
}
}
echo '';
}

Rate this post

4 of 5 based on 2090 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us