owner->rules->load_rules(); // Check if discount is active if ( $this->owner->discount_rules == null ) return ''; // Exit if no rules // Load Product List $this->owner->rules->set_product_list(); global $product; $post_id = $product->get_id(); $product = wc_get_product( $post_id ); // Divi Theme Page Builder Loading issue - Fix if(!$product){ return; } /* * ver @ 4.3.3 * Tax Settings */ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); $cartPrice = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price(); $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax( $product, array ( 'price' => $cartPrice ) ); $rules = $this->owner->discount_rules; $price = $priceIncTax ? $priceIncTax : $cartPrice; $prodLists = $this->owner->product_lists; $variations = $this->owner->variations; $discountedPrice = $this->owner->discountProductPrice; $discountProductMaxPrice = $this->owner->discountProductMaxPrice; $discountProductMinPrice = $this->owner->discountProductMinPrice; // Variable products often have an empty parent price — use variation price range. if ( ( $price == '' || $price == 0 ) && $product->is_type( 'variable' ) ) { $variation_price_map = $product->get_variation_prices( true ); if ( ! empty( $variation_price_map['price'] ) ) { $price = (float) min( $variation_price_map['price'] ); if ( ! $discountProductMinPrice ) { $discountProductMinPrice = (float) min( $variation_price_map['price'] ); } if ( ! $discountProductMaxPrice ) { $discountProductMaxPrice = (float) max( $variation_price_map['price'] ); } } } if ( $price == '' || $price == 0 ) return ''; $pricing_table = call_user_func_array ( array ( new AWDP_viewPricingTable(), 'pricin_table' ), array ( $rules, $product, $price, $post_id, $prodLists, $variations, $discountedPrice, $discountProductMaxPrice, $discountProductMinPrice ) ); echo $pricing_table; } // Price View HTML public function get_product_price_html ( $item_price, $product ) { if ( !$product ) return $item_price; $updatedPrice = ''; $post_id = $product->get_id(); /* * Set / Reset Attribute Value * Support for Feed Plugin - Set sale price attribute key as 'acowdp_sale_price' * ver @ 4.4.4 */ if ( metadata_exists ( 'post', $post_id, AWDP_Feed_Attribute ) ) { update_post_meta ( $post_id, AWDP_Feed_Attribute, '' ); } else { add_post_meta ( $post_id, AWDP_Feed_Attribute, '' ); } // End if ( is_admin() && !wp_doing_ajax() ) return $item_price; // Load discount rules $this->owner->rules->load_rules(); // Check if discount is active if ( $this->owner->discount_rules == null ) return $item_price; // Exit if no rules // Load Product List $this->owner->rules->set_product_list(); /* * ver @ 4.3.3 * Tax Settings */ $tax_display_mode = get_option( 'woocommerce_tax_display_shop' ); $cartPrice = $product->get_sale_price() ? $product->get_sale_price() : $product->get_price(); $priceIncTax = ( 'incl' === $tax_display_mode ) ? wc_get_price_including_tax( $product, array ( 'price' => $cartPrice ) ) : wc_get_price_excluding_tax( $product, array ( 'price' => $cartPrice ) ); $rules = $this->owner->discount_rules; $price = $priceIncTax ? $priceIncTax : $cartPrice; $prodLists = $this->owner->product_lists; $variations = $this->owner->variations; $cartRules = $this->owner->awdp_cart_rules; // Display-only original/struck-through price (sale by default; regular when setting is on). $display_price = awdp_get_product_strikeout_display_price( $product ); // if( $this->owner->converted_rate == '' && $item->get_ID() != '' ) { // $this->owner->converted_rate = $this->owner->utilities->get_con_unit($item, $price, true); // } if ( $price == '' || $price == 0 ) return $item_price; $viewPrice = call_user_func_array ( array ( new AWDP_viewProductPrice(), 'product_price' ), array ( $rules, $price, $post_id, $product, $prodLists, $cartRules, $item_price, $display_price ) ); if ( is_array ( $viewPrice ) ) { $updatedPrice = $viewPrice['itemPrice']; $this->owner->discountProductPrice = $viewPrice['discountedPrice']; $this->owner->discountProductMaxPrice = $viewPrice['discountedMaxPrice']; $this->owner->discountProductMinPrice = $viewPrice['discountedMinPrice']; } return $updatedPrice ? $updatedPrice : $item_price; } // WCPA Get Variation Price public function show_offer_message(){ global $product; if ( ! is_a( $product, 'WC_Product' ) ) { return ''; } $offer_desc_config = get_option('awdp_disc_desc_config') ? get_option('awdp_disc_desc_config') : []; $offerMsgEnable = array_key_exists ( 'enable_dismessage', $offer_desc_config ) ? $offer_desc_config['enable_dismessage'] : ''; if ( ! $offerMsgEnable ) { return ''; } // Load discount rules $this->owner->rules->load_rules(); // Check if discount is active if ( $this->owner->discount_rules == null ) return ''; // Exit if no rules // Load Product List $this->owner->rules->set_product_list(); $productid = $product->get_id(); $result = ''; $offer_rule = array_key_exists ( 'dismessage_rule', $offer_desc_config ) ? $offer_desc_config['dismessage_rule'] : ''; $checkML = call_user_func ( array ( new AWDP_ML(), 'is_default_lan' ), '' ); $currentLang = !$checkML ? call_user_func ( array ( new AWDP_ML(), 'current_language' ), '' ) : ''; $langSettings = get_option('awdp_settings_lang_options') ? get_option('awdp_settings_lang_options') : []; /* * @ver 4.1.7 * Offer description for all active rules (earlier version displays description on all products) */ $show_description = false; if ( !empty( $this->owner->discount_rules ) ) { foreach ( $this->owner->discount_rules as $rule ) { if ( $offer_rule != '' && $offer_rule != 'all_active' && $rule['id'] != $offer_rule ) { continue; } // Check if this rule is applicable to the current product $checkItem = $this->owner->rules->get_items_to_apply_discount ( $product, $rule ); if ( $checkItem ) { if ( ! awdp_user_qualifies_for_discount_rule( $rule ) ) { continue; } // A valid active discount rule is applicable to this product, show description $show_description = true; break; } } } if ( $show_description ) { // $productlist = ( $offer_rule != '' && $offer_rule != 'all_active' ) ? ( get_post_meta ( $offer_rule, 'discount_product_list', true ) ) : ''; // // Check in product list // if ( '' == $productlist || 0 == $productlist || $all_prods == true || ( !empty ( $list_products ) && in_array ( $productid, $list_products ) ) || ( isset ( $this->owner->product_lists[$productlist] ) && in_array ( $productid, $this->owner->product_lists[$productlist] ) ) ) { /* * ver @ 4.4.8 * WMPL Support offer description */ if ( !empty ($langSettings) && array_key_exists ( $currentLang, $langSettings ) ) { $offer_desc = array_key_exists ( 'dismessage', $langSettings[$currentLang] ) ? $langSettings[$currentLang]['dismessage'] : ( array_key_exists ( 'dismessage', $offer_desc_config ) ? $offer_desc_config['dismessage'] : '' ); } else { $offer_desc = array_key_exists ( 'dismessage', $offer_desc_config ) ? $offer_desc_config['dismessage'] : ''; } // $offer_desc = array_key_exists ( 'dismessage', $offer_desc_config ) ? $offer_desc_config['dismessage'] : ''; $offer_fontsize = ( array_key_exists ( 'dismessage_fontsize', $offer_desc_config ) && $offer_desc_config['dismessage_fontsize'] !== '' ) ? $offer_desc_config['dismessage_fontsize'] : 12; $offer_paddding_lm = ( array_key_exists ( 'dismessage_paddding_lm', $offer_desc_config ) && $offer_desc_config['dismessage_paddding_lm'] !== '' ) ? $offer_desc_config['dismessage_paddding_lm'] : 10; $offer_paddding_tp = ( array_key_exists ( 'dismessage_paddding_tp', $offer_desc_config ) && $offer_desc_config['dismessage_paddding_tp'] !== '' ) ? $offer_desc_config['dismessage_paddding_tp'] : 10; $offer_radius = ( array_key_exists ( 'dismessage_radius', $offer_desc_config ) && $offer_desc_config['dismessage_radius'] !== '' ) ? $offer_desc_config['dismessage_radius'] : 0; $offer_color = array_key_exists ( 'dismessage_color', $offer_desc_config ) ? $offer_desc_config['dismessage_color'] : ''; $offer_background = array_key_exists ( 'dismessage_background', $offer_desc_config ) ? $offer_desc_config['dismessage_background'] : ''; $border_top_width = ( array_key_exists ( 'border_top_width', $offer_desc_config ) && $offer_desc_config['border_top_width'] !== '' ) ? $offer_desc_config['border_top_width'].'px' : '0px'; $border_right_width = ( array_key_exists ( 'border_right_width', $offer_desc_config ) && $offer_desc_config['border_right_width'] !== '' ) ? ' '.$offer_desc_config['border_right_width'].'px' : ' 0px'; $border_bottom_width = ( array_key_exists ( 'border_bottom_width', $offer_desc_config ) && $offer_desc_config['border_bottom_width'] !== '' ) ? ' '.$offer_desc_config['border_bottom_width'].'px' : ' 0px'; $border_left_width = ( array_key_exists ( 'border_left_width', $offer_desc_config ) && $offer_desc_config['border_left_width'] !== '' ) ? ' '.$offer_desc_config['border_left_width'].'px' : ' 0px'; $offer_border_color = array_key_exists ( 'offer_border_color', $offer_desc_config ) ? $offer_border_color_tmp = $offer_desc_config['offer_border_color'] : ''; $offer_border_color = isset($offer_border_color_tmp) ? $offer_border_color_tmp : ''; $customStyle = 'display: inline-block; font-size: '.$offer_fontsize.'px;padding: '.$offer_paddding_tp.'px '.$offer_paddding_lm.'px;border-radius: '.$offer_radius.'px;'; $customStyle .= $offer_color ? 'color: '.$offer_color.';' : ''; $customStyle .= $offer_background ? 'background: '.$offer_background.';' : ''; $customStyle .= $offer_border_color ? 'border-color: '.$offer_border_color.';' : ''; $customStyle .= ( $border_top_width || $border_right_width || $border_bottom_width || $border_left_width ) ? 'border-width: '.$border_top_width.$border_right_width.$border_bottom_width.$border_left_width.';' : ''; $result = '
'; // } } echo $result; } /** * Total Dynamic Pricing savings for the current cart (line-price + coupon discounts). * * @return float */ public function get_cart_saved_amount() { $total = 0.0; if ( empty( $this->owner->discounts ) || ! WC()->cart ) { return $total; } foreach ( $this->owner->discounts as $ruleid => $discounts ) { if ( empty( $discounts['discounts'] ) || ! is_array( $discounts['discounts'] ) ) { continue; } $discount_type = isset( $discounts['discount_type'] ) ? $discounts['discount_type'] : ''; foreach ( $discounts['discounts'] as $discount ) { if ( ! isset( $discount['discount'] ) || $discount['discount'] === '' || $discount['discount'] === null ) { continue; } $calc_discount = AWDP_Discount_Application::normalize_discount_amount( $discount['discount'] ); // Per-unit product discounts are stored per item; multiply by line qty for the order total saved. if ( AWDP_Discount_Application::coupon_amount_is_per_unit( $discount_type, $ruleid ) ) { $qty = isset( $discount['quantity'] ) ? (int) $discount['quantity'] : 1; $calc_discount = $calc_discount * max( 1, $qty ); } $total += $calc_discount; } } return (float) $total; } // Cart Message public function wdpCartMessage(){ if ( ! WC()->cart ) { return; } $customStyle = ''; $result = ''; $checkML = call_user_func( array( new AWDP_ML(), 'is_default_lan' ), '' ); $currentLang = ! $checkML ? call_user_func( array( new AWDP_ML(), 'current_language' ), '' ) : ''; $langSettings = get_option( 'awdp_settings_lang_options' ) ? get_option( 'awdp_settings_lang_options' ) : array(); // Include line-price discounts (no virtual coupon) and coupon-based discounts. $coupons_amount = $this->get_cart_saved_amount(); $custom_message_settings = get_option( 'awdp_custom_msg_settings' ) ? get_option( 'awdp_custom_msg_settings' ) : array(); $custom_message_status = array_key_exists( 'custom_message_status', $custom_message_settings ) ? $custom_message_settings['custom_message_status'] : false; if ( $coupons_amount > 0 && $custom_message_status ) { /* * ver @ 4.4.8 * WMPL Support custom message */ if ( ! empty( $langSettings ) && array_key_exists( $currentLang, $langSettings ) ) { $custom_message = array_key_exists( 'custom_message', $langSettings[ $currentLang ] ) ? $langSettings[ $currentLang ]['custom_message'] : ( array_key_exists( 'custom_message', $custom_message_settings ) ? $custom_message_settings['custom_message'] : '' ); } else { $custom_message = array_key_exists( 'custom_message', $custom_message_settings ) ? $custom_message_settings['custom_message'] : ''; } $custom_message_linheight = array_key_exists( 'custom_message_linheight', $custom_message_settings ) ? $custom_message_settings['custom_message_linheight'] : ''; $custom_message_fontsize = array_key_exists( 'custom_message_fontsize', $custom_message_settings ) ? $custom_message_settings['custom_message_fontsize'] : ''; $custom_message_position = array_key_exists( 'custom_message_position', $custom_message_settings ) ? $custom_message_settings['custom_message_position'] : ''; $custom_message_paddding_lm = array_key_exists( 'custom_message_paddding_lm', $custom_message_settings ) ? $custom_message_settings['custom_message_paddding_lm'] : ''; $custom_message_paddding_tp = array_key_exists( 'custom_message_paddding_tp', $custom_message_settings ) ? $custom_message_settings['custom_message_paddding_tp'] : ''; $custom_message_border_radius = array_key_exists( 'custom_message_border_radius', $custom_message_settings ) ? $custom_message_settings['custom_message_border_radius'] : ''; $custom_message_border_top_width = array_key_exists( 'custom_message_border_top_width', $custom_message_settings ) ? $custom_message_settings['custom_message_border_top_width'] . 'px ' : ''; $custom_message_border_right_width = array_key_exists( 'custom_message_border_right_width', $custom_message_settings ) ? $custom_message_settings['custom_message_border_right_width'] . 'px ' : ''; $custom_message_border_bottom_width = array_key_exists( 'custom_message_border_bottom_width', $custom_message_settings ) ? $custom_message_settings['custom_message_border_bottom_width'] . 'px ' : ''; $custom_message_border_left_width = array_key_exists( 'custom_message_border_left_width', $custom_message_settings ) ? $custom_message_settings['custom_message_border_left_width'] . 'px' : ''; $custom_message_border_color = array_key_exists( 'custom_message_border_color', $custom_message_settings ) ? $custom_message_settings['custom_message_border_color'] : ''; $custom_message_background = array_key_exists( 'custom_message_background', $custom_message_settings ) ? $custom_message_settings['custom_message_background'] : ''; $custom_message_color = array_key_exists( 'custom_message_color', $custom_message_settings ) ? $custom_message_settings['custom_message_color'] : ''; $customStyle .= 'font-size: ' . $custom_message_fontsize . 'px;padding: ' . $custom_message_paddding_tp . 'px ' . $custom_message_paddding_lm . 'px;border-radius: ' . $custom_message_border_radius . 'px;'; $customStyle .= $custom_message_linheight ? 'line-height: ' . $custom_message_linheight . ( is_numeric( $custom_message_linheight ) && $custom_message_linheight > 3 ? 'px' : '' ) . ';' : ''; $customStyle .= $custom_message_color ? 'color: ' . $custom_message_color . ';' : ''; $customStyle .= $custom_message_background ? 'background: ' . $custom_message_background . ';' : ''; $customStyle .= $custom_message_border_color ? 'border-color: ' . $custom_message_border_color . ';' : ''; $customStyle .= $custom_message_position ? 'text-align: ' . $custom_message_position . ';' : ''; $customStyle .= ( $custom_message_border_top_width || $custom_message_border_right_width || $custom_message_border_bottom_width || $custom_message_border_left_width ) ? 'border-width: ' . $custom_message_border_top_width . $custom_message_border_right_width . $custom_message_border_bottom_width . $custom_message_border_left_width . ';' : ''; // Filter the saved message before inserting wc_price(), whose markup wp_kses_post() would strip. $message = $custom_message ? str_replace( '[discount]', wc_price( $coupons_amount ), wp_kses_post( $custom_message ) ) : esc_html__( "You've saved ", 'aco-woo-dynamic-pricing' ) . wc_price( $coupons_amount ) . esc_html__( ' on this order', 'aco-woo-dynamic-pricing' ); $result = '