Advertisement
nshelper

Untitled

Apr 16th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. public function getCompoSiteChildsSubTotal( $product, $component_data, $cart_item_key, $global_quantity ) {
  2. $new_subtotal = 0;
  3. $composite_stored_data = $product->getComponentsData();
  4. $cart = WC()->cart->get_cart();
  5.  
  6. $product_blog = $product->get_meta( 'blog_id' );
  7. switch_to_blog( $product_blog );
  8.  
  9. foreach ( $composite_stored_data as $key => $component_item ) {
  10. if( isset( $component_data['selection_data'][$key] ) ) {
  11. if ( $component_data['selection_data'][$key] > 0 ) {
  12. // Variation selected
  13. if ( isset( $component_data['selection_variation_data'][$key] ) && $component_data['selection_variation_data'][$key] > 0 ) {
  14. $child_product = wc_get_product( $component_data['selection_variation_data'][$key] );
  15. } else {
  16. $child_product = wc_get_product( $component_data['selection_data'][$key] );
  17. }
  18. YITH_WCP_Frontend::markProductAsCompositeProcessed( $child_product, yit_get_base_product_id( $product ), $key );
  19. // Read child items of composite products
  20. foreach ( $cart as $cart_item_key_ass => $value ) {
  21. if ( isset( $value['yith_wcp_child_component_data'] ) ) {
  22. $cart_child_meta_data = $value['yith_wcp_child_component_data'];
  23. if ( isset( $cart_child_meta_data['yith_wcp_cart_parent_key'] ) && $cart_child_meta_data['yith_wcp_cart_parent_key'] == $cart_item_key ) {
  24. if ( $cart_child_meta_data['yith_wcp_component_key'] == $key ) {
  25. $child_quantity = $component_data['selection_quantity'][$key];
  26. $wcp_component_item = $cart_child_meta_data['yith_wcp_component_parent_object']->getComponentItemByKey( $cart_child_meta_data['yith_wcp_component_key'] );
  27. $sold_individually = isset( $wcp_component_item['sold_individually'] ) && $wcp_component_item['sold_individually'] ? $wcp_component_item['sold_individually'] : false;
  28. if ( $sold_individually ) {
  29. $single_total = yit_get_display_price( $child_product ) * $child_quantity;
  30. } else {
  31. $single_total = yit_get_display_price( $child_product ) * $global_quantity;
  32. }
  33. $new_subtotal += $single_total;
  34. break;
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }
  42.  
  43. restore_current_blog();
  44.  
  45. return apply_filters( 'yith_wcp_composite_children_subtotal', $new_subtotal, $product , $component_data , $cart_item_key , $global_quantity );
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement