WPC Product Bundles for WooCommerce, by WPclever.net
Add provided code to functions.php and update Settings.
Calculation option “Use prices modified by other plugins” must be ON.
System option “Suppress other pricing plugins in frontend” must be OFF.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
class WDP_WOOSB_Compatibility { const KEY = 'wpclever_woosb'; const WDP_VERSION = '2.2.4'; const TARGET_VERSION = '3.8.3'; public function is_required() { return defined( 'WOOSB_VERSION' ); } public function admin_install() { } public function remove_admin_hooks() { } /** * @param WDP_Price_Display $price_display */ public function install( $price_display ) { add_filter( 'wdp_cart_item_data_before_apply', array( $this, 'wdp_cart_item_data_before_apply' ), 10, 2 ); add_filter( 'wdp_original_cart_item_data', array( $this, 'wdp_original_cart_item_data' ), 10, 1 ); add_filter( 'wdp_skip_cart_item', array( $this, 'wdp_skip_cart_item' ), 10, 3 ); add_action( 'woocommerce_before_calculate_totals', array( $this, 'sanitize_cart_items' ), 10, 0 ); add_action( 'woocommerce_cart_id', array( $this, 'woocommerce_cart_id' ), 10, 1 ); } public function remove_hooks() { remove_filter( 'wdp_cart_item_data_before_apply', array( $this, 'wdp_cart_item_data_before_apply' ), 10 ); remove_filter( 'wdp_original_cart_item_data', array( $this, 'wdp_original_cart_item_data' ), 10 ); remove_filter( 'wdp_skip_cart_item', array( $this, 'wdp_skip_cart_item' ), 10 ); } /** * "Bundle" tries to add item hash in his meta, but misses, because we change it. * Unfortunately, we have to check and sanitize every time * * @see WPcleverWoosb::woosb_add_to_cart_items() */ public function sanitize_cart_items() { foreach ( WC()->cart->cart_contents as $cart_item_key => $cart_item ) { if ( empty( $cart_item['data'] ) ) { unset( WC()->cart->cart_contents[ $cart_item_key ] ); } } } public function woocommerce_cart_id( $cart_id ) { $this->sanitize_cart_items(); return $cart_id; } public function wdp_cart_item_data_before_apply( $cart_item_data, $original_cart_item_data ) { if ( isset( $original_cart_item_data['woosb_ids'], $original_cart_item_data['woosb_fixed_price'] ) ) { $cart_item_data['woosb_ids'] = $original_cart_item_data['woosb_ids']; $cart_item_data['woosb_fixed_price'] = $original_cart_item_data['woosb_fixed_price']; } return $cart_item_data; } public function wdp_original_cart_item_data( $original_cart_item_data ) { if ( isset( $original_cart_item_data['woosb_ids'] ) ) { $original_cart_item_data = array(); } return $original_cart_item_data; } public function wdp_skip_cart_item( $skip, $item, $product ) { // ignore product inside bundle if ( isset( $item['woosb_parent_id'] ) ) { $skip = true; } return $skip; } } $cmp = new WDP_WOOSB_Compatibility(); if ( $cmp->is_required() ) { $cmp->install( null ); } |