Getting configuration option in cart

[ad_1]

Hi there,

The configuration is stored in the configurator_data attribute.
You can access it like this:

foreach( WC()->cart->get_cart() as $cart_item ) {

$product_id = $cart_item['product_id'];

if ( mkl_pc_is_configurable( $product_id ) && isset( ( $cart_item['configurator_data'] ) ) ) {

foreach( $cart_item['configurator_data'] as $selected_choice ) {
// dump the layer name
var_dump( $selected_choice->get_layer( 'name' ) );
// dump the choice name
var_dump( $selected_choice->get_choice( 'name' ) );
}
// Alternatively, you can use the simpler configurator_data_raw data
var_dump( $cart_item['configurator_data_raw'] );
}

}

Marc

  • This reply was modified 3 hours, 13 minutes ago by Marc Lacroix. Reason: Fixed code

Thread Starter
smams

(@smams)

That’s brilliant. Thank you for your quick response.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer