class WDP_WCPA_Custom_Compatibility { const KEY = 'acowebs-woo-custom-product-addons'; const WDP_VERSION = '2.2.4'; const TARGET_VERSION = '4.3.10'; protected $tm_keys = array( 'wcpa_data', 'wcpa_cart_rules', 'wcpa_options_price_end', 'wcpa_options_price_start', 'wcpa_options_price', ); public function is_required() { return class_exists( 'WCPA_Front_End' ); } public function admin_install() { } public function remove_admin_hooks() { } /** * @param WDP_Price_Display $price_display */ public function install( $price_display ) { add_action( 'init', function () { 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_save_cart_item_keys', array( $this, 'wdp_save_cart_item_keys' ), 10, 1 ); add_filter( "wdp_get_product_regular_price", array( $this, 'wdp_get_product_any_price' ), 10, 3 ); add_filter( "wdp_get_product_sale_price", array( $this, 'wdp_get_product_any_price' ), 10, 3 ); add_filter( "wdp_get_product_initial_price", array( $this, 'wdp_get_product_any_price' ), 10, 3 ); } ); } public function remove_hooks() { if ( did_action( 'init' ) ) { 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_save_cart_item_keys', array( $this, 'wdp_save_cart_item_keys' ), 10 ); remove_filter( "wdp_get_product_regular_price", array( $this, 'wdp_get_product_any_price' ), 10 ); remove_filter( "wdp_get_product_sale_price", array( $this, 'wdp_get_product_any_price' ), 10 ); remove_filter( "wdp_get_product_initial_price", array( $this, 'wdp_get_product_any_price' ), 10 ); } } public function wdp_cart_item_data_before_apply( $cart_item_data, $original_cart_item_data ) { foreach ( $this->tm_keys as $key ) { if ( isset( $original_cart_item_data[ $key ] ) ) { $cart_item_data[ $key ] = $original_cart_item_data[ $key ]; } } return $cart_item_data; } public function wdp_original_cart_item_data( $original_cart_item_data ) { foreach ( $this->tm_keys as $key ) { if ( isset( $original_cart_item_data[ $key ] ) ) { unset( $original_cart_item_data[ $key ] ); } } return $original_cart_item_data; } public function wdp_save_cart_item_keys( $keys ) { return array_merge( $keys, $this->tm_keys ); } public function wdp_get_product_any_price( $price, $product, $item_meta ) { if ( $price !== "" && isset( $item_meta['wcpa_options_price_start'] ) && isset( $item_meta['wcpa_options_price_end'] ) ) { $wcpa_price = floatval( $item_meta['wcpa_options_price_start'] ) + floatval( $item_meta['wcpa_options_price_end'] ); $mc = new WCPA_MC(); $wcpa_price = $mc->mayBeConvert($wcpa_price); if (isset($item_meta['wcpa_cart_rules']['pric_overide_base_price']) && $item_meta['wcpa_cart_rules']['pric_overide_base_price'] === true) { $price = max($wcpa_price, $price); } else if (isset($item_meta['wcpa_cart_rules']['pric_overide_base_price_if_gt_zero']) && $item_meta['wcpa_cart_rules']['pric_overide_base_price_if_gt_zero'] === true && $wcpa_price > 0) { $price = $wcpa_price; } else { $price = $wcpa_price + floatval($price); } if ($price < 0) { $price = 0; } } return $price; } } $comp = new WDP_WCPA_Custom_Compatibility(); if($comp->is_required()) { $comp->install(null); }
Woocommerce Custom Product Addons, by Acowebs Print
Created by: Alex Prokaev
Modified on: Tue, 28 Apr, 2020 at 6:27 PM
Did you find it helpful? Yes No
Send feedbackSorry we couldn't be helpful. Help us improve this article with your feedback.