Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getCompoSiteChildsSubTotal( $product, $component_data, $cart_item_key, $global_quantity ) {
- $new_subtotal = 0;
- $composite_stored_data = $product->getComponentsData();
- $cart = WC()->cart->get_cart();
- $product_blog = $product->get_meta( 'blog_id' );
- switch_to_blog( $product_blog );
- foreach ( $composite_stored_data as $key => $component_item ) {
- if( isset( $component_data['selection_data'][$key] ) ) {
- if ( $component_data['selection_data'][$key] > 0 ) {
- // Variation selected
- if ( isset( $component_data['selection_variation_data'][$key] ) && $component_data['selection_variation_data'][$key] > 0 ) {
- $child_product = wc_get_product( $component_data['selection_variation_data'][$key] );
- } else {
- $child_product = wc_get_product( $component_data['selection_data'][$key] );
- }
- YITH_WCP_Frontend::markProductAsCompositeProcessed( $child_product, yit_get_base_product_id( $product ), $key );
- // Read child items of composite products
- foreach ( $cart as $cart_item_key_ass => $value ) {
- if ( isset( $value['yith_wcp_child_component_data'] ) ) {
- $cart_child_meta_data = $value['yith_wcp_child_component_data'];
- if ( isset( $cart_child_meta_data['yith_wcp_cart_parent_key'] ) && $cart_child_meta_data['yith_wcp_cart_parent_key'] == $cart_item_key ) {
- if ( $cart_child_meta_data['yith_wcp_component_key'] == $key ) {
- $child_quantity = $component_data['selection_quantity'][$key];
- $wcp_component_item = $cart_child_meta_data['yith_wcp_component_parent_object']->getComponentItemByKey( $cart_child_meta_data['yith_wcp_component_key'] );
- $sold_individually = isset( $wcp_component_item['sold_individually'] ) && $wcp_component_item['sold_individually'] ? $wcp_component_item['sold_individually'] : false;
- if ( $sold_individually ) {
- $single_total = yit_get_display_price( $child_product ) * $child_quantity;
- } else {
- $single_total = yit_get_display_price( $child_product ) * $global_quantity;
- }
- $new_subtotal += $single_total;
- break;
- }
- }
- }
- }
- }
- }
- }
- restore_current_blog();
- return apply_filters( 'yith_wcp_composite_children_subtotal', $new_subtotal, $product , $component_data , $cart_item_key , $global_quantity );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement