Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pramodjodhani/cd0e1a43c2cccc0818fac55bb013ee22 to your computer and use it in GitHub Desktop.
Save pramodjodhani/cd0e1a43c2cccc0818fac55bb013ee22 to your computer and use it in GitHub Desktop.
Iconic Linked Variations - display non-variation attributes to cart.
<?php
/**
* Iconic Linked Variations - Force display non LV attributes in cart.
*
* @param array $item_data
* @param array $cart_item
*
* @return array
*/
function iconic_display_non_lv_attributes_in_cart( $item_data, $cart_item ) {
// TODO: replace this with your attribute slug.
$lv = Iconic_WLV_Product::get_product_linked_variations( $cart_item['product_id'] );
if ( empty( $lv ) ) {
return $item_data;
}
// Use the parent's attributes.
$product = wc_get_product( $cart_item['product_id'] );
$atts = $product->get_attributes();
if ( empty( $atts[ $attribute_slug ] ) ) {
return $item_data;
}
$terms = $atts[ $attribute_slug ]->get_terms();
$terms_names = wp_list_pluck( $terms, 'name' );
if ( empty( $terms_names ) ) {
return $item_data;
}
$item_data[] = array(
'key' => 'Color',
'value' => implode( ',', $terms_names ),
'display' => '',
);
return $item_data;
}
add_filter( 'woocommerce_get_item_data', 'iconic_display_non_lv_attributes_in_cart', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment