Skip to content

Instantly share code, notes, and snippets.

@marcusig
Last active June 18, 2022 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusig/dc095146463a1f0b4130648480dc4f63 to your computer and use it in GitHub Desktop.
Save marcusig/dc095146463a1f0b4130648480dc4f63 to your computer and use it in GitHub Desktop.
Add the group name in the cart and order
<?php
// Filter the data in the cart / checkout
add_filter( 'mkl_pc/wc_cart_get_item_data/choice', function( $choice_data, $layer ) {
$parent_id = $layer->get_choice( 'parent' );
if ( $parent_id && is_callable( [ $layer, 'get_choice_by_id' ] ) ) {
$parent = $layer->get_choice_by_id( $parent_id );
if ( $parent && isset( $parent[ 'name' ] ) ) {
$choice_data['value'] = $parent[ 'name' ] . ', ' . $choice_data['value'];
}
}
return $choice_data;
}, 20, 2 );
// Filter the data in the order
add_filter( 'mkl_pc/order_created/save_layer_meta', function( $choice_data, $layer ) {
$parent_id = $layer->get_choice( 'parent' );
if ( $parent_id && is_callable( [ $layer, 'get_choice_by_id' ] ) ) {
$parent = $layer->get_choice_by_id( $parent_id );
if ( $parent && isset( $parent[ 'name' ] ) ) {
$choice_data['value'] = $parent[ 'name' ] . ', ' . $choice_data['value'];
}
}
return $choice_data;
}, 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment