| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| class WWPP_Bundle_Product_Page_Fix {
|
| private static $bundled_item_args = null;
|
|
|
| public static function capture( $args, $product ) {
|
| if ( isset( $args['input_name'] ) && false !== strpos( $args['input_name'], 'bundle_quantity_' ) ) {
|
| self::$bundled_item_args = $args;
|
| }
|
| return $args;
|
| }
|
|
|
| public static function restore( $args, $product ) {
|
| if ( null !== self::$bundled_item_args ) {
|
| $args = self::$bundled_item_args;
|
| self::$bundled_item_args = null;
|
| }
|
| return $args;
|
| }
|
| }
|
|
|
| add_filter( 'woocommerce_quantity_input_args', array( 'WWPP_Bundle_Product_Page_Fix', 'capture' ), 10, 2 );
|
| add_filter( 'woocommerce_quantity_input_args', array( 'WWPP_Bundle_Product_Page_Fix', 'restore' ), 12, 2 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| class WWPP_Bundle_Cart_Fix {
|
| private static $bundled_qtys = array();
|
|
|
| public static function capture( $cart ) {
|
| if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
|
| self::$bundled_qtys = array();
|
| foreach ( $cart->get_cart() as $key => $item ) {
|
| if ( ! empty( $item['bundled_by'] ) ) {
|
| self::$bundled_qtys[ $key ] = $item['quantity'];
|
| }
|
| }
|
| }
|
|
|
| public static function restore( $cart ) {
|
| if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
|
| foreach ( self::$bundled_qtys as $key => $qty ) {
|
| if ( isset( $cart->cart_contents[ $key ] ) ) {
|
| $cart->cart_contents[ $key ]['quantity'] = $qty;
|
| }
|
| }
|
| self::$bundled_qtys = array();
|
| }
|
| }
|
|
|
| add_action( 'woocommerce_before_calculate_totals', array( 'WWPP_Bundle_Cart_Fix', 'capture' ), 9 );
|
| add_action( 'woocommerce_before_calculate_totals', array( 'WWPP_Bundle_Cart_Fix', 'restore' ), 11 );
|
| |
| |
Comments