public function vtwpr_process_discount() { //and print discount info... global $woocommerce, $vtwpr_cart, $vtwpr_cart_item, $vtwpr_info, $vtwpr_rules_set, $vtwpr_rule, $wpsc_coupons; /* //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //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(); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ //echo '<br>BEGIN PROCESS_DISCOUNT!!<br>' ; //mwnecho //calc discounts $vtwpr_info['current_processing_request'] = 'cart'; $vtwpr_apply_rules = new VTWPR_Apply_Rules(); /* echo '$vtwpr_cart = <pre>'.print_r($vtwpr_cart, true).'</pre>' ; echo '$vtwpr_rules_set = <pre>'.print_r($vtwpr_rules_set, true).'</pre>' ; wp_die( __('<strong>Looks like you\'re running an older version of WordPress, you need to be running at least WordPress 3.3 to use the Varktech Wholesale Pricing plugin.</strong>', 'vtwpr'), __('VT Wholesale Pricing not compatible - WP', 'vtwpr'), array('back_link' => true)); */ /* ************************************************* Load this info into session variables, to begin the DATA CHAIN - global to session back to global global to session - in vtwpr_process_discount session to global - in vtwpr_woo_validate_order access global - in vtwpr_post_purchase_maybe_save_log_info ************************************************* */ if (!isset($_SESSION)) { session_start(); header("Cache-Control: no-cache"); header("Pragma: no-cache"); } $contents_total = $woocommerce->cart->cart_contents_total; $applied_coupons = $woocommerce->cart->applied_coupons; $data_chain = array(); $data_chain[] = $vtwpr_rules_set; $data_chain[] = $vtwpr_cart; $data_chain[] = vtwpr_get_current_user_role(); //v1.0.3 $data_chain[] = $contents_total; $data_chain[] = $applied_coupons; $_SESSION['data_chain'] = serialize($data_chain); //echo '<br>End PROCESS_DISCOUNT!!<br>' ; //mwnecho //echo 'process_discount $contents_total= ' .$contents_total. '<br>'; //echo 'process_discount $applied_coupons= ' .$applied_coupons. '<br>'; return; }
function vtwpr_wholesale_pricing_msgs_advanced($atts) { global $vtwpr_rules_set, $vtwpr_setup_options; extract(shortcode_atts(array(group1_type => 'cart', group1_and_or_wholestore_msgs_only => 'and', group1_wholestore_msgs_only => 'no', and_or_group1_to_group2 => 'and', group2_rules => '', group2_and_or_roles => 'and', group2_roles => '', and_or_group2_to_group3 => 'and', group3_product_category => '', group3_and_or_plugin_category => 'or', group3_plugin_category => ''), $atts)); //override default value with supplied parameters... vtwpr_set_selected_timezone(); $vtwpr_rules_set = get_option('vtwpr_rules_set'); $output = '<div class="vtwpr-advanced-deal-msg-area">'; $msg_counter = 0; //echo 'incoming attributes= ' .$atts. '<br>'; //mwnt $sizeof_rules_set = sizeof($vtwpr_rules_set); for ($i = 0; $i < $sizeof_rules_set; $i++) { if ($vtwpr_rules_set[$i]->rule_status != 'publish') { continue; } $rule_is_date_valid = vtwpr_rule_date_validity_test($i); if (!$rule_is_date_valid) { continue; } if (defined('VTWPR_PRO_DIRNAME') && $vtwpr_setup_options['use_lifetime_max_limits'] == 'yes') { //IP is immediately available, check against Lifetime limits $rule_has_reached_lifetime_limit = vtwpr_rule_lifetime_validity_test($i, 'shortcode'); if ($rule_has_reached_lifetime_limit) { continue; } } $status = array('group1_type' => '', 'group1_wholestore_msgs_only' => '', 'group2_rules' => '', 'group2_roles' => '', 'group3_product_category' => '', 'group3_plugin_category' => '', 'group1' => '', 'group2' => '', 'group3' => '', 'total' => ''); //SET Status success/failed for each parameter switch ($group1_type) { case 'cart': if ($vtwpr_rules_set[$i]->rule_execution_type == 'display') { $status['group1_type'] = 'failed'; } else { $status['group1_type'] = 'success'; } break; case 'catalog': if ($vtwpr_rules_set[$i]->rule_execution_type == 'cart') { $status['group1_type'] = 'failed'; } else { $status['group1_type'] = 'success'; } break; case 'all': $status['group1_type'] = 'success'; break; default: $status['group1_type'] = 'failed'; break; } if ($group1_wholestore_msgs_only == 'yes') { if ($vtwpr_rules_set[$i]->inPop == 'wholeStore' || $vtwpr_rules_set[$i]->actionPop == 'wholeStore') { $status['group1_wholestore_msgs_only'] = 'success'; } else { $status['group1_wholestore_msgs_only'] = 'failed'; } } else { $status['group1_wholestore_msgs_only'] = 'success'; } if ($group2_roles > ' ') { $userRole = vtwpr_get_current_user_role(); $userRole_name = translate_user_role($userRole); $group2_roles_array = explode(",", $group2_roles); //remove comma separator, make list an array if (in_array($userRole_name, $group2_roles_array)) { $status['group2_roles'] = 'success'; } else { $status['group2_roles'] = 'failed'; } } else { $status['group2_roles'] = 'success'; } if ($group2_rules > ' ') { $group2_rules_array = explode(",", $group2_rules); //remove comma separator, make list an array if (in_array($vtwpr_rules_set[$i]->post_id, $group2_rules_array)) { $status['group2_rules'] = 'success'; } else { $status['group2_rules'] = 'failed'; } } else { $status['group2_rules'] = 'success'; } if ($group3_product_category > ' ') { $group3_product_category_array = explode(",", $group3_product_category); //remove comma separator, make list an array if (array_intersect($vtwpr_rules_set[$i]->prodcat_in_checked, $group3_product_category_array) || array_intersect($vtwpr_rules_set[$i]->prodcat_out_checked, $group3_product_category_array)) { $status['group3_product_category'] = 'success'; } else { $status['group3_product_category'] = 'failed'; } } else { $status['group3_product_category'] = 'success'; } if ($group3_plugin_category > ' ') { $group3_plugin_category_array = explode(",", $group3_plugin_category); //remove comma separator, make list an array if (array_intersect($vtwpr_rules_set[$i]->rulecat_in_checked, $group3_plugin_category_array) || array_intersect($vtwpr_rules_set[$i]->rulecat_out_checked, $group3_plugin_category_array)) { $status['group3_plugin_category'] = 'success'; } else { $status['group3_plugin_category'] = 'failed'; } } else { $status['group3_plugin_category'] = 'success'; } //Evaluate status settings //evaluate group1 switch ($group1_and_or_wholestore_msgs_only) { case 'and': if ($status['group1_type'] == 'success' && $status['group1_wholestore_msgs_only'] == 'success') { $status['group1'] = 'success'; } else { $status['group1'] = 'failed'; } break; case 'or': if ($status['group1_type'] == 'success' || $status['group1_wholestore_msgs_only'] == 'success') { $status['group1'] = 'success'; } else { $status['group1'] = 'failed'; } break; default: $status['group1'] = 'failed'; break; } //evaluate group2 switch ($group2_and_or_roles) { case 'and': if ($status['group2_rules'] == 'success' && $status['group2_roles'] == 'success') { $status['group2'] = 'success'; } else { $status['group2'] = 'failed'; } break; case 'or': if ($status['group2_rules'] == 'success' || $status['group2_roles'] == 'success') { $status['group2'] = 'success'; } else { $status['group2'] = 'failed'; } break; default: $status['group2'] = 'failed'; break; } //evaluate group3 switch ($group3_and_or_plugin_category) { case 'and': if ($status['group3_product_category'] == 'success' && $status['group3_plugin_category'] == 'success') { $status['group3'] = 'success'; } else { $status['group3'] = 'failed'; } break; case 'or': if ($status['group3_product_category'] == 'success' || $status['group3_plugin_category'] == 'success') { $status['group3'] = 'success'; } else { $status['group3'] = 'failed'; } break; default: $status['group3'] = 'failed'; break; } //evaluate all 3 groups together switch (true) { case $and_or_group1_to_group2 == 'and' && $and_or_group2_to_group3 == 'and': if ($status['group1'] == 'success' && $status['group2'] == 'success' && $status['group3'] == 'success') { $status['total'] = 'success'; } else { $status['total'] = 'failed'; } break; case $and_or_group1_to_group2 == 'and' && $and_or_group2_to_group3 == 'or': if ($status['group1'] == 'success' && $status['group2'] == 'success' || $status['group3'] == 'success') { $status['total'] = 'success'; } else { $status['total'] = 'failed'; } break; case $and_or_group1_to_group2 == 'or' && $and_or_group2_to_group3 == 'and': if (($status['group1'] == 'success' || $status['group2'] == 'success') && $status['group3'] == 'success') { $status['total'] = 'success'; } else { $status['total'] = 'failed'; } break; case $and_or_group1_to_group2 == 'or' && $and_or_group2_to_group3 == 'or': if ($status['group1'] == 'success' || $status['group2'] == 'success' || $status['group3'] == 'success') { $status['total'] = 'success'; } else { $status['total'] = 'failed'; } break; } if ($status['total'] == 'success') { $msg_counter++; $output .= '<span class="vtwpr-advanced-deal-msg" id="vtwpr-advanced-deal-msg-' . $vtwpr_rules_set[$i]->post_id . '">'; $output .= stripslashes($vtwpr_rules_set[$i]->discount_product_full_msg); $output .= '</span>'; $output .= '<span class="vtwpr-line-skip-with-display-block"></span>'; } } //end 'for' loop if ($msg_counter == 0) { return; } //close owning div $output .= '</div>'; // vtwpr_enqueue_front_end_css(); return $output; }
function vtwpr_maybe_get_price_single_product($product_id, $price = null) { global $post, $vtwpr_info; //echo ' cv001a product_id= ' . $product_id. ' price= ' .$price. '<br>' ; //mwnt //store product-specific session info if (!isset($_SESSION)) { session_start(); header("Cache-Control: no-cache"); header("Pragma: no-cache"); } /* echo 'vtwpr_info <pre>'.print_r($vtwpr_info, true).'</pre>' ; session_start(); //mwntest echo 'SESSION data <pre>'.print_r($_SESSION, true).'</pre>' ; echo '<pre>'.print_r($vtwpr_rules_set, true).'</pre>' ; echo '<pre>'.print_r($vtwpr_cart, true).'</pre>' ; echo '<pre>'.print_r($vtwpr_setup_options, true).'</pre>' ; echo '<pre>'.print_r($vtwpr_info, true).'</pre>' ; wp_die( __('<strong>Looks like you\'re running an older version of WordPress, you need to be running at least WordPress 3.3 to use the Varktech Minimum Purchase plugin.</strong>', 'vtmin'), __('VT Minimum Purchase not compatible - WP', 'vtmin'), array('back_link' => true)); */ //if already in the session variable... => this routine can be called multiple times in displaying a single catalog price. check first if already done. // echo 'IN THE ROUTINE, $product_id= ' .$product_id.'<br>' ; // echo 'SESSION data <pre>'.print_r($_SESSION, true).'</pre>' ; if (isset($_SESSION['vtwpr_product_session_info_' . $product_id])) { $vtwpr_info['product_session_info'] = $_SESSION['vtwpr_product_session_info_' . $product_id]; //will be a problem in Ajax... $current_time_in_seconds = time(); $user_role = vtwpr_get_current_user_role(); if ($current_time_in_seconds - $vtwpr_info['product_session_info']['session_timestamp_in_seconds'] > '3600' || $user_role != $vtwpr_info['product_session_info']['user_role']) { //current user role not the same as prev vtwpr_apply_rules_to_single_product($product_id, $price); } } else { //First time obtaining the info, also moves the data to $vtwpr_info vtwpr_apply_rules_to_single_product($product_id, $price); // vtwpr_apply_rules_to_vargroup_or_single($product_id, $price); } //$vtwpr_info['product_session_info'] is loaded by this time... return; }
public function vtwpr_is_user_in_role_list($checked_list) { if (!is_user_logged_in()) { return false; } if (strpos($checked_list, vtwpr_get_current_user_role())) { //if role is in previously checked_list return true; } else { return false; } }