function vtprd_move_vtprd_single_product_to_session($product_id) { global $post, $wpdb, $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_info, $vtprd_setup_options, $vtprd_rules_set; vtprd_debug_options(); //v1.0.9.4 $short_msg_array = array(); $full_msg_array = array(); $msg_already_done = 'no'; $show_yousave_one_some_msg = ''; //v1.0.8.0 //auditTrail keyed to rule_id, so foreach is necessary foreach ($vtprd_cart->cart_items[0]->cartAuditTrail as $key => $row) { //parent product vargroup on sale, individual product variation may not be on sale. // send an additional sale msg for the varProd parent group... $show_yousave_one_some_msg = ''; if ($vtprd_setup_options['show_yousave_one_some_msg'] == 'yes') { if (!$show_yousave_one_some_msg) { $rulesetKey = $row['ruleset_occurrence']; switch ($vtprd_rules_set[$rulesetKey]->inPop_varProdID_parentLit) { case 'one': $show_yousave_one_some_msg = __('One of these are on Sale', 'vtprd'); break; case 'some': $show_yousave_one_some_msg = __('Some of these are on Sale', 'vtprd'); break; case 'all': //all are on sale, handled as normal. break; default: //handled as normal. break; } } } if ($row['rule_short_msg'] > ' ') { $short_msg_array[] = $row['rule_short_msg']; $full_msg_array[] = $row['rule_full_msg']; } } /* if $vtprd_cart->cart_level_status == 'rejected' no discounts found how to handle yousave display, etc.... If no yousave, return 'false' */ if ($vtprd_cart->cart_level_status == 'rejected') { $vtprd_cart->cart_items[0]->discount_price = 0; $vtprd_cart->cart_items[0]->yousave_total_amt = 0; $vtprd_cart->cart_items[0]->yousave_total_pct = 0; } //needed for wp-e-commerce!!!!!!!!!!! // if = 'yes', display of 'yousave' becomes 'save FROM' and doesn't change!!!!!!! // $product_variations_sw = vtprd_test_for_variations($product_id); $product_variations_sw = ''; //v1.0.9.0 begin vtprd_get_cart_html_prices('single', 'catalog'); //************************* //v1.0.9.0 begin refactored //************************* if ($vtprd_cart->cart_items[0]->yousave_total_amt > 0) { $list_price = $vtprd_cart->cart_items[0]->db_unit_price_list; //v1.0.8.8 begin //if taxation should be applied to list price, do so here if (get_option('woocommerce_calc_taxes') == 'yes' && get_option('woocommerce_prices_include_tax') == 'no' && get_option('woocommerce_tax_display_cart') == 'incl') { $list_price = vtprd_get_price_including_tax($product_id, $list_price); } //v1.0.8.8 end //v1.1.1 begin ADDED to include opposite side if (get_option('woocommerce_calc_taxes') == 'yes' && get_option('woocommerce_prices_include_tax') == 'yes' && get_option('woocommerce_tax_display_cart') == 'excl') { $list_price = vtprd_get_price_excluding_tax($product_id, $list_price); } $vtprd_cart->cart_items[0]->product_list_price_catalog_correctly_taxed = $list_price; //v1.1.1 end $vtprd_cart->cart_items[0]->product_list_price_html_woo = woocommerce_price($list_price); } //v1.0.9.0 end $product_orig_price_html_woo = ''; //v1.1.0.9 //v1.0.9.3 begin //load info for old_price used later if ($vtprd_cart->cart_items[0]->yousave_total_amt > 0 && $vtprd_setup_options['show_catalog_price_crossout'] == 'yes') { switch (true) { //v1.1.0.4 begin case $vtprd_cart->cart_items[0]->product_is_on_special == 'yes': /* case ( ($vtprd_cart->cart_items[0]->db_unit_price_special > 0 ) && ($vtprd_cart->cart_items[0]->db_unit_price_special < $vtprd_cart->cart_items[0]->db_unit_price_list ) ) : //there is a discount... */ //v1.1.0.4 end $product_orig_price = $vtprd_cart->cart_items[0]->db_unit_price_special; //special_price needs formatting ... break; default: $product_orig_price = $vtprd_cart->cart_items[0]->db_unit_price_list; break; } $product_orig_price_html_woo = wc_price($product_orig_price); $product = false; //v1.1.1 needed below! if (get_option('woocommerce_calc_taxes') == 'yes') { if (get_option('woocommerce_prices_include_tax') == 'yes') { if (get_option('woocommerce_tax_display_shop') == 'excl') { $product = get_product($product_id); $product_orig_price_excl_tax = vtprd_get_price_excluding_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_html_woo = wc_price($product_orig_price_excl_tax); } } else { if (get_option('woocommerce_tax_display_shop') == 'incl') { $product = get_product($product_id); $product_orig_price_incl_tax = vtprd_get_price_including_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_html_woo = wc_price($product_orig_price_incl_tax); } } } /* switch (true) { case ( (get_option( 'woocommerce_tax_display_shop' ) == 'excl' ) : $oldprice = $vtprd_cart_item->product_catalog_price_displayed_incl_tax_woo; break; case ( (get_option( 'woocommerce_tax_display_shop' ) == 'incl' ) && (get_option( 'woocommerce_tax_display_cart' ) == 'excl') ) : $oldprice = $vtprd_cart_item->product_catalog_price_displayed_excl_tax_woo; break; default: $oldprice = $vtprd_cart_item->product_catalog_price_displayed; break; } $product = get_product( $product_id ); $product_orig_price_incl_tax = vtprd_get_price_including_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_html_woo = wc_price($product_orig_price_incl_tax); $product = get_product( $product_id ); $product_orig_price_incl_tax = vtprd_get_price_including_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_incl_tax_html_woo = wc_price($product_orig_price_incl_tax); $product_orig_price_excl_tax = vtprd_get_price_excluding_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_excl_tax_html_woo = wc_price($product_orig_price_excl_tax); */ } //v1.0.9.3 end //------------------ //v1.1.1 begin //***************************************************** // PLUGIN:: woocommerce-product-addons //***************************************************** // Test for and Mark all addon-related products $product_has_addons = false; if (class_exists('WC_Product_Addons')) { //********* //if we are on a variation, get the parent id. product_addons are attributes of the parent product only - but mark all products! //********* $post_parent = wp_get_post_parent_id($product_id); if ($post_parent > 0) { $use_this_product_id = $post_parent; } else { $use_this_product_id = $product_id; } $product_addons = array_filter((array) get_post_meta($use_this_product_id, '_product_addons', true)); if (is_array($product_addons) && sizeof($product_addons) > 0) { $product_has_addons = true; } //used in vtprd_maybe_get_price if (isset($_SESSION['single_product_first_time_' . $product_id]) && $_SESSION['single_product_first_time_' . $product_id] == 'yes') { $_SESSION['single_product_first_time_' . $product_id] = 'no'; } else { $_SESSION['single_product_first_time_' . $product_id] = 'yes'; } } //***************************************************** // PLUGIN:: woocommerce-measurement-price-calculator //***************************************************** // Test for and Mark all calculator-related products $product_has_calculator = false; if (class_exists('WC_Measurement_Price_Calculator')) { //********* //if we are on a variation, get the parent id. product_calculator are attributes of the parent product only - but mark all products! //********* $post_parent = wp_get_post_parent_id($product_id); if ($post_parent > 0) { $use_this_product_id = $post_parent; } else { $use_this_product_id = $product_id; } $price_calculator = get_post_meta($use_this_product_id, '_wc_price_calculator', true); $price_calculator_rules = get_post_meta($use_this_product_id, '_wc_price_calculator_pricing_rules', true); if (is_array($price_calculator) && sizeof($price_calculator) > 0 || is_array($price_calculator_rules) && sizeof($price_calculator_rules) > 0) { $product_has_calculator = true; } } //v1.1.1 end //------------------ $vtprd_info['product_session_info'] = array('product_list_price' => $vtprd_cart->cart_items[0]->db_unit_price_list, 'product_list_price_html_woo' => $vtprd_cart->cart_items[0]->product_list_price_html_woo, 'product_unit_price' => $vtprd_cart->cart_items[0]->db_unit_price, 'product_special_price' => $vtprd_cart->cart_items[0]->db_unit_price_special, 'product_discount_price' => $vtprd_cart->cart_items[0]->product_discount_price_woo, 'product_discount_price_html_woo' => $vtprd_cart->cart_items[0]->product_discount_price_html_woo, 'product_discount_price_incl_tax_woo' => $vtprd_cart->cart_items[0]->product_discount_price_incl_tax_woo, 'product_discount_price_excl_tax_woo' => $vtprd_cart->cart_items[0]->product_discount_price_excl_tax_woo, 'product_discount_price_incl_tax_html_woo' => $vtprd_cart->cart_items[0]->product_discount_price_incl_tax_html_woo, 'product_discount_price_excl_tax_html_woo' => $vtprd_cart->cart_items[0]->product_discount_price_excl_tax_html_woo, 'product_discount_price_suffix_html_woo' => $vtprd_cart->cart_items[0]->product_discount_price_suffix_html_woo, 'product_catalog_yousave_total_amt_incl_tax_woo' => $vtprd_cart->cart_items[0]->product_catalog_yousave_total_amt_incl_tax_woo, 'product_catalog_yousave_total_amt_excl_tax_woo' => $vtprd_cart->cart_items[0]->product_catalog_yousave_total_amt_excl_tax_woo, 'product_orig_price_html_woo' => $product_orig_price_html_woo, 'product_is_on_special' => $vtprd_cart->cart_items[0]->product_is_on_special, 'product_yousave_total_amt' => $vtprd_cart->cart_items[0]->yousave_total_amt, 'product_yousave_total_pct' => $vtprd_cart->cart_items[0]->yousave_total_pct, 'product_rule_short_msg_array' => $short_msg_array, 'product_rule_full_msg_array' => $full_msg_array, 'product_has_variations' => $product_variations_sw, 'session_timestamp_in_seconds' => time(), 'user_role' => vtprd_get_current_user_role(), 'product_in_rule_allowing_display' => $vtprd_cart->cart_items[0]->product_in_rule_allowing_display, 'show_yousave_one_some_msg' => $show_yousave_one_some_msg, 'this_is_a_parent_product_with_variations' => $vtprd_cart->cart_items[0]->this_is_a_parent_product_with_variations, 'pricing_by_rule_array' => $vtprd_cart->cart_items[0]->pricing_by_rule_array, 'product_id' => $product_id, 'product_has_calculator' => $product_has_calculator, 'product_has_addons' => $product_has_addons, 'product_list_price_catalog_correctly_taxed' => $vtprd_cart->cart_items[0]->product_list_price_catalog_correctly_taxed); //v1.0.9.0 end if (!isset($_SESSION)) { session_start(); header("Cache-Control: no-cache"); header("Pragma: no-cache"); } //store session id 'vtprd_product_session_info_[$product_id]' $_SESSION['vtprd_product_session_info_' . $product_id] = $vtprd_info['product_session_info']; //initialize vtprd_cart to clear all discount values... //v1.0.7.8 $vtprd_cart = new vtprd_Cart(); //v1.0.7.8 }
public function vtprd_process_discount() { //and print discount info... //error_log( print_r( 'Function begin - vtprd_process_discount', true ) ); global $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_info, $vtprd_rules_set, $vtprd_rule, $wpsc_coupons, $vtprd_setup_options; //v1.0.9.0 /* //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //In order to prevent recursive executions, test for a TIMESTAMP if (isset($_SESSION['process_discount_timestamp'])) { $previous_process_discount_timestamp = $_SESSION['process_discount_timestamp']; $current_process_discount_timestamp = time(); if ( ($current_time_in_seconds - $previous_process_discount_timestamp) > '1' ) { //session data older than 1 second $_SESSION['process_discount_timestamp'] = time(); } else { return; } } else { $_SESSION['process_discount_timestamp'] = time(); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ //calc discounts $vtprd_info['current_processing_request'] = 'cart'; $vtprd_apply_rules = new VTPRD_Apply_Rules(); //v1.0.9.0 begin //load the vtprd cart html fields, for later use - IF we are showing the discount in-line in unit price if ($vtprd_setup_options['discount_taken_where'] == 'discountUnitPrice') { $catalog_or_inline = 'inline'; } else { $catalog_or_inline = null; } vtprd_get_cart_html_prices('process discount', $catalog_or_inline); //v1.1.1 //v1.0.9.0 end /* ************************************************* Load this info into session variables, to begin the DATA CHAIN - global to session back to global global to session - in vtprd_process_discount session to global - in vtprd_woo_validate_order access global - in vtprd_post_purchase_maybe_save_log_info ************************************************* */ if (!isset($_SESSION)) { session_start(); header("Cache-Control: no-cache"); header("Pragma: no-cache"); } //v1.1.0.9 begin need to clear this out if (isset($_SESSION['data_chain'])) { $contents = $_SESSION['data_chain']; unset($_SESSION['data_chain'], $contents); } ///v1.1.0.9 end $contents_total = $woocommerce->cart->cart_contents_total; $applied_coupons = $woocommerce->cart->applied_coupons; $data_chain = array(); $data_chain[] = $vtprd_rules_set; $data_chain[] = $vtprd_cart; $data_chain[] = vtprd_get_current_user_role(); //v1.0.7.2 $data_chain[] = $contents_total; $data_chain[] = $applied_coupons; $_SESSION['data_chain'] = serialize($data_chain); return; }
function vtprd_move_vtprd_single_product_to_session($product_id) { global $post, $wpdb, $woocommerce, $vtprd_cart, $vtprd_cart_item, $vtprd_info, $vtprd_setup_options, $vtprd_rules_set; vtprd_debug_options(); //v1.0.9.4 $short_msg_array = array(); $full_msg_array = array(); $msg_already_done = 'no'; $show_yousave_one_some_msg = ''; //v1.0.8.0 //auditTrail keyed to rule_id, so foreach is necessary foreach ($vtprd_cart->cart_items[0]->cartAuditTrail as $key => $row) { //parent product vargroup on sale, individual product variation may not be on sale. // send an additional sale msg for the varProd parent group... $show_yousave_one_some_msg = ''; if ($vtprd_setup_options['show_yousave_one_some_msg'] == 'yes') { if (!$show_yousave_one_some_msg) { $rulesetKey = $row['ruleset_occurrence']; switch ($vtprd_rules_set[$rulesetKey]->inPop_varProdID_parentLit) { case 'one': $show_yousave_one_some_msg = __('One of these are on Sale', 'vtprd'); break; case 'some': $show_yousave_one_some_msg = __('Some of these are on Sale', 'vtprd'); break; case 'all': //all are on sale, handled as normal. break; default: //handled as normal. break; } } } if ($row['rule_short_msg'] > ' ') { $short_msg_array[] = $row['rule_short_msg']; $full_msg_array[] = $row['rule_full_msg']; } } /* if $vtprd_cart->cart_level_status == 'rejected' no discounts found how to handle yousave display, etc.... If no yousave, return 'false' */ if ($vtprd_cart->cart_level_status == 'rejected') { $vtprd_cart->cart_items[0]->discount_price = 0; $vtprd_cart->cart_items[0]->yousave_total_amt = 0; $vtprd_cart->cart_items[0]->yousave_total_pct = 0; } //needed for wp-e-commerce!!!!!!!!!!! // if = 'yes', display of 'yousave' becomes 'save FROM' and doesn't change!!!!!!! // $product_variations_sw = vtprd_test_for_variations($product_id); $product_variations_sw = ''; //v1.0.9.0 begin $number_of_times = 1; vtprd_get_cart_html_prices($number_of_times, 'catalog'); //************************* //v1.0.9.0 begin refactored //************************* if ($vtprd_cart->cart_items[0]->yousave_total_amt > 0) { $list_price = $vtprd_cart->cart_items[0]->db_unit_price_list; //v1.0.8.8 begin //if taxation should be applied to list price, do so here if (get_option('woocommerce_calc_taxes') == 'yes' && get_option('woocommerce_prices_include_tax') == 'no' && get_option('woocommerce_tax_display_cart') == 'incl') { $list_price = vtprd_get_price_including_tax($product_id, $list_price); //error_log( print_r( 'vtprd_get_price_including_tax 001, price= ' .$list_price , true ) ); } //v1.0.8.8 end $vtprd_cart->cart_items[0]->product_list_price_html_woo = woocommerce_price($list_price); } //v1.0.9.0 end //v1.0.9.3 begin //load info for old_price used later if ($vtprd_cart->cart_items[0]->yousave_total_amt > 0 && $vtprd_setup_options['show_catalog_price_crossout'] == 'yes') { switch (true) { //v1.1.0.4 begin case $vtprd_cart->cart_items[0]->product_is_on_special == 'yes': /* case ( ($vtprd_cart->cart_items[0]->db_unit_price_special > 0 ) && ($vtprd_cart->cart_items[0]->db_unit_price_special < $vtprd_cart->cart_items[0]->db_unit_price_list ) ) : //there is a discount... */ //v1.1.0.4 end $product_orig_price = $vtprd_cart->cart_items[0]->db_unit_price_special; //special_price needs formatting ... break; default: $product_orig_price = $vtprd_cart->cart_items[0]->db_unit_price_list; break; } $product_orig_price_html_woo = wc_price($product_orig_price); if (get_option('woocommerce_calc_taxes') == 'yes') { if (get_option('woocommerce_prices_include_tax') == 'yes') { if (get_option('woocommerce_tax_display_shop') == 'excl') { $product = get_product($product_id); $product_orig_price_excl_tax = vtprd_get_price_excluding_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_html_woo = wc_price($product_orig_price_excl_tax); } } else { if (get_option('woocommerce_tax_display_shop') == 'incl') { $product = get_product($product_id); $product_orig_price_incl_tax = vtprd_get_price_including_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_html_woo = wc_price($product_orig_price_incl_tax); } } } /* switch (true) { case ( (get_option( 'woocommerce_tax_display_shop' ) == 'excl' ) : $oldprice = $vtprd_cart_item->product_catalog_price_displayed_incl_tax_woo; break; case ( (get_option( 'woocommerce_tax_display_shop' ) == 'incl' ) && (get_option( 'woocommerce_tax_display_cart' ) == 'excl') ) : $oldprice = $vtprd_cart_item->product_catalog_price_displayed_excl_tax_woo; break; default: $oldprice = $vtprd_cart_item->product_catalog_price_displayed; break; } $product = get_product( $product_id ); $product_orig_price_incl_tax = vtprd_get_price_including_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_html_woo = wc_price($product_orig_price_incl_tax); $product = get_product( $product_id ); $product_orig_price_incl_tax = vtprd_get_price_including_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_incl_tax_html_woo = wc_price($product_orig_price_incl_tax); $product_orig_price_excl_tax = vtprd_get_price_excluding_tax_forced($product_id, $product_orig_price, $product); $product_orig_price_excl_tax_html_woo = wc_price($product_orig_price_excl_tax); */ } //v1.0.9.3 end $vtprd_info['product_session_info'] = array('product_list_price' => $vtprd_cart->cart_items[0]->db_unit_price_list, 'product_list_price_html_woo' => $vtprd_cart->cart_items[0]->product_list_price_html_woo, 'product_unit_price' => $vtprd_cart->cart_items[0]->db_unit_price, 'product_special_price' => $vtprd_cart->cart_items[0]->db_unit_price_special, 'product_discount_price' => $vtprd_cart->cart_items[0]->product_discount_price_woo, 'product_discount_price_html_woo' => $vtprd_cart->cart_items[0]->product_discount_price_html_woo, 'product_discount_price_incl_tax_woo' => $vtprd_cart->cart_items[0]->product_discount_price_incl_tax_woo, 'product_discount_price_excl_tax_woo' => $vtprd_cart->cart_items[0]->product_discount_price_excl_tax_woo, 'product_discount_price_incl_tax_html_woo' => $vtprd_cart->cart_items[0]->product_discount_price_incl_tax_html_woo, 'product_discount_price_excl_tax_html_woo' => $vtprd_cart->cart_items[0]->product_discount_price_excl_tax_html_woo, 'product_discount_price_suffix_html_woo' => $vtprd_cart->cart_items[0]->product_discount_price_suffix_html_woo, 'product_catalog_yousave_total_amt_incl_tax_woo' => $vtprd_cart->cart_items[0]->product_catalog_yousave_total_amt_incl_tax_woo, 'product_catalog_yousave_total_amt_excl_tax_woo' => $vtprd_cart->cart_items[0]->product_catalog_yousave_total_amt_excl_tax_woo, 'product_orig_price_html_woo' => $product_orig_price_html_woo, 'product_is_on_special' => $vtprd_cart->cart_items[0]->product_is_on_special, 'product_yousave_total_amt' => $vtprd_cart->cart_items[0]->yousave_total_amt, 'product_yousave_total_pct' => $vtprd_cart->cart_items[0]->yousave_total_pct, 'product_rule_short_msg_array' => $short_msg_array, 'product_rule_full_msg_array' => $full_msg_array, 'product_has_variations' => $product_variations_sw, 'session_timestamp_in_seconds' => time(), 'user_role' => vtprd_get_current_user_role(), 'product_in_rule_allowing_display' => $vtprd_cart->cart_items[0]->product_in_rule_allowing_display, 'show_yousave_one_some_msg' => $show_yousave_one_some_msg, 'this_is_a_parent_product_with_variations' => $vtprd_cart->cart_items[0]->this_is_a_parent_product_with_variations, 'pricing_by_rule_array' => $vtprd_cart->cart_items[0]->pricing_by_rule_array, 'product_id' => $product_id); //v1.0.9.0 end /* error_log( print_r( 'product_session_info= ' , true ) ); error_log( var_export($vtprd_info['product_session_info'], true ) ); error_log( print_r( '$vtprd_cart->cart_items[0]= ' , true ) ); error_log( var_export($vtprd_cart->cart_items[0], true ) ); */ if (!isset($_SESSION)) { session_start(); header("Cache-Control: no-cache"); header("Pragma: no-cache"); } //store session id 'vtprd_product_session_info_[$product_id]' $_SESSION['vtprd_product_session_info_' . $product_id] = $vtprd_info['product_session_info']; //initialize vtprd_cart to clear all discount values... //v1.0.7.8 $vtprd_cart = new vtprd_Cart(); //v1.0.7.8 }