WooCommerce Product Add-ons
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 |
add_filter('wpo_update_cart_cart_item_meta', function ($cart_item_meta, $item) { return array_merge($cart_item_meta, array( 'addons' => isset($item['addons']) ? $item['addons'] : null, )); }, 10, 2); add_filter('wpo_update_cart_loaded_product', function ($loaded_product, $item) { return array_merge($loaded_product, array( 'addons' => isset($item['addons']) ? $item['addons'] : null, 'readonly_price' => $item['line_subtotal'] / $item['quantity'], 'readonly_custom_meta_fields_html' => isset($item['addons']) ? wc_get_formatted_cart_item_data($item) : '', )); }, 10, 2); add_filter('wpo_product_calc_line_subtotal', function ($calc, $item) { return isset($item['addons']) && $item['addons'] ? false : $calc; }, 10, 2); add_filter('wpo_get_item_by_product', function ($product, $cart_item_data) { return array_merge($product, array( 'addons' => isset($cart_item_data['addons']) ? $cart_item_data['addons'] : null, 'readonly_price' => $cart_item_data['line_subtotal'] / $cart_item_data['quantity'], )); }, 10, 2); add_filter('wpo_cart_item_is_price_readonly', function ($is_readonly, $cart_item_data) { return isset($cart_item_data['addons']) && $cart_item_data['addons'] ? true : $is_readonly; }, 10, 2); |