Last active
June 18, 2022 12:11
-
-
Save marcusig/dc095146463a1f0b4130648480dc4f63 to your computer and use it in GitHub Desktop.
Add the group name in the cart and order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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