types = Array( 'percent_total_amount' => __('Percentage of cart total amount', 'aco-woo-dynamic-pricing'), 'percent_product_price' => __('Percentage of product price', 'aco-woo-dynamic-pricing'), 'fixed_product_price' => __('Fixed price of product price', 'aco-woo-dynamic-pricing'), 'fixed_cart_amount' => __('Fixed price of cart total amount', 'aco-woo-dynamic-pricing'), 'cart_quantity' => __('Quantity based discount', 'aco-woo-dynamic-pricing') ); } /** * * Ensures only one instance of AWDP is loaded or can be loaded. * * @since 1.0.0 * @static * @see WordPress_Plugin_Template() * @return Main AWDP instance */ public static function instance($file = '', $version = '1.0.0') { if (is_null(self::$_instance)) { self::$_instance = new self($file, $version); } return self::$_instance; } /** * @return bool */ public function isActive() { return $this->_active; } // Cart Price View public function cart_discount_items($item_price, $cart_item) { $prod_ID = $cart_item['data']->get_data()['slug']; if( $this->converted_rate == '' && $cart_item['data']->get_ID() != '' ) { $this->converted_rate = $this->get_con_unit($cart_item['data'], wc_remove_number_precision($this->discounted_price[$prod_ID])); } if ($this->discount_rules != false && sizeof($this->discount_rules) >= 1 && $this->check_discount($prod_ID) && false == $this->awdp_cart_rules) { $discounted_price = abs(wc_remove_number_precision($this->discounted_price[$prod_ID])); $actual_price = isset ($this->actual_price) ? (array_key_exists($prod_ID, $this->actual_price) ? $this->actual_price[$prod_ID] : $cart_item['data']->get_data()['price']) : $cart_item['data']->get_data()['price']; $quantity = $cart_item['quantity']; if (($discounted_price > 0.0000000001 && ($discounted_price < $actual_price)) || $discounted_price == 0) { $item_price = wc_format_sale_price($actual_price * $this->converted_rate, $discounted_price * $this->converted_rate); } else if ($discounted_price > $actual_price) { $item_price = wc_format_sale_price($actual_price * $this->converted_rate, $discounted_price * $this->converted_rate); } } return $item_price; } // Price View HTML public function get_product_price_html($item_price, $product) { $prod_ID = $product->get_data()['slug']; if( $this->converted_rate == '' && $product->get_ID() != '' ) { $this->converted_rate = $this->get_con_unit($product, wc_remove_number_precision($this->discounted_price[$prod_ID])); } // Variable Product if ($product->is_type('variable')) { $variations = $product->get_available_variations(); if($variations) { $wdp_max_price = $product->get_variation_price( 'max', true ); $wdp_min_price = $product->get_variation_price( 'min', true ); $variation_prices = []; $regular_prices = []; foreach($variations as $variation) { array_push($variation_prices, $variation['display_price']); } $min_price = min($variation_prices); $max_price = max($variation_prices); if( $min_price == $wdp_min_price && $max_price == $wdp_max_price ) { return $item_price; } else { if ( $min_price !== $max_price ) { // $item_price = wc_format_price_range( $min_price * $this->converted_rate, $max_price * $this->converted_rate ); $item_price = '
'.wc_format_price_range( $wdp_min_price, $wdp_max_price ).' '.wc_format_price_range( $min_price * $this->converted_rate, $max_price * $this->converted_rate ).'
| ' . $awdp_qn_label . ' | '; $tr_pr = '||||||||||||||||||||||||||
| ' . $awdp_pc_label . ' | '; } else { $table = '
| ' . $awdp_qn_label . ' | ' . $awdp_pc_label . ' | ' . $quantity_rule['start_range'] . ' | '; } else if ($quantity_rule['end_range']) { $tr_qn .= '' . $quantity_rule['start_range'] . ' - ' . $quantity_rule['end_range'] . ' | '; } else { $tr_qn .= '' . $quantity_rule['start_range'] . ' + | '; } if ($discounted_new_min_price == $discounted_new_max_price) { $tr_pr .= '' . $discounted_new_min_price . ' | '; } else { $tr_pr .= '' . $discounted_new_min_price . ' - ' . $discounted_new_max_price . ' | '; } } else { if ($quantity_rule['start_range'] == $quantity_rule['end_range']) { $table .= '
| ' . $quantity_rule['start_range'] . ' | '; if ($discounted_new_min_price == $discounted_new_max_price) { $table .= '' . $discounted_new_min_price . ' | '; } else { $table .= '' . $discounted_new_min_price . ' - ' . $discounted_new_max_price . ' | '; } $table .= '
| ' . $quantity_rule['start_range'] . ' - ' . $quantity_rule['end_range'] . ' | '; if ($discounted_new_min_price == $discounted_new_max_price) { $table .= '' . $discounted_new_min_price . ' | '; } else { $table .= '' . $discounted_new_min_price . ' - ' . $discounted_new_max_price . ' | '; } $table .= '
| ' . $quantity_rule['start_range'] . ' + | '; if ($discounted_new_min_price == $discounted_new_max_price) { $table .= '' . $discounted_new_min_price . ' | '; } else { $table .= '' . $discounted_new_min_price . ' - ' . $discounted_new_max_price . ' | '; } $table .= '' . $quantity_rule['start_range'] . ' | '; } else if ($quantity_rule['end_range']) { $tr_qn .= '' . $quantity_rule['start_range'] . ' - ' . $quantity_rule['end_range'] . ' | '; } else { $tr_qn .= '' . $quantity_rule['start_range'] . ' + | '; } $tr_pr .= '' . $discounted_new_price . ' | '; } else { if ($quantity_rule['start_range'] == $quantity_rule['end_range']) { $table .= '
| ' . $quantity_rule['start_range'] . ' | ' . $discounted_new_price . ' | |
| ' . $quantity_rule['start_range'] . ' - ' . $quantity_rule['end_range'] . ' | ' . $discounted_new_price . ' | |
| ' . $quantity_rule['start_range'] . ' + | ' . $discounted_new_price . ' |