1 ){ /* get all set percentage options , removing zero here */ $percentage_options = array_filter($wppizza_options['order_settings']['tips_percentage_options']);//remove any zero option that was set /* sort */ asort($percentage_options); /* loop */ foreach($percentage_options as $pc){ $pcTips = ($payment_amount_subtotal / 100) * $pc; $pcTips = wppizza_format_price_float($pcTips); $tips_percentage_options[] = array('label' => $pc.'%', 'tip' => $pcTips . $optionIdent, 'pc' => $pc ); } } /*********************************************************************************************************************** tips round up options depending on value ***********************************************************************************************************************/ $tips_roundup_options = array(); //get base value (integer, without decimals) $amountInteger = (int)$payment_amount_subtotal; //set steps increase if($payment_amount_subtotal <= 10 ){ $steps = 0.5 ;//0.50 $ steps } elseif($payment_amount_subtotal <= 100 ){ $steps = 1 ;//1 $ steps } elseif($payment_amount_subtotal <= 250 ){ $steps = 5 ;//5 $ steps } elseif($payment_amount_subtotal <= 500 ){ $steps = 10 ;//10 $ steps } elseif($payment_amount_subtotal <= 1000 ){ $steps = 25 ;//25 $ steps } elseif($payment_amount_subtotal <= 2000 ){ $steps = 50 ;//50 $ steps } elseif($payment_amount_subtotal <= 5000 ){ $steps = 100 ;//100 $ steps } elseif($payment_amount_subtotal <= 10000 ){ $steps = 250 ;//250 $ steps } else{ $steps = 500 ;//500 $ steps, I guess this will do ... } $steps = apply_filters(WPPIZZA_SLUG.'_filter_tips_steps', $steps, $payment_amount_subtotal, $orderData); /*************************** calculate the options ***************************/ // find the first sensible depending on steps (so we use 125,130, 135 etc for a 122 bill and not 127, 132 etc) $loopCount = $steps < 10 ? 10 : abs((int)$steps); for($i = 1; $i <= $loopCount ; $i++){ //if steps are not integers, the is_int check wont work, so will simply set the next one that's > current amount if(!is_int($steps)){ $nextStep = $amountInteger + ($i * $steps); if($nextStep > $payment_amount_subtotal){ $firstTipOption = $nextStep; break; } }else{ $nextStep = $amountInteger + $i; if(is_int($nextStep / $steps)){ $firstTipOption = $nextStep; break; } } } //get all options starting from first determined for($i = 0; $i < $maxSteps ; $i++){ $tipStep = $firstTipOption + ($i * $steps); $stepsTips = $tipStep - $payment_amount_subtotal ; $tips_roundup_options[] = array('label' => wppizza_format_price($tipStep), 'tip' => $stepsTips); } /*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/* # # generate markup # *\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*\/*/ //set 'amount' to be selected - overwritten as required $select_amount_option = true; /************************* select markup *************************/ $markup_select = ''; $markup_select .= ''; /************************** direct input **************************/ $required_attribute = ''; /* is pickup */ if(!empty($orderData['summary']['self_pickup']) && !empty($wppizza_options['order_form'][$ctips_key]['required_on_pickup']) ){ $required_attribute = 'required = "required" '; } /* is delivery */ if(empty($orderData['summary']['self_pickup']) && !empty($wppizza_options['order_form'][$ctips_key]['required']) ){ $required_attribute = 'required = "required" '; } //adding - unused - subtotal before tips as data-subtotal just for info if we want to doublecheck tip percentage calculations for example $markup_input = ''; /************************** label in div, before **************************/ $markup_label = ''; //currently not using a lable as it's added to dropdown as first option #$markup_label = !empty($wppizza_options['localization']['tips']) ? '
'.$wppizza_options['localization']['tips'] . '
' : '' ; /*---------------------------------------------------------------------------------------------- ORDERPAGE ONLY - DROPDOWN AND INPUT TEXT FIELD input and select inverted here as we are floating:right wrap in div for possible error messages (if set to be required for example) ----------------------------------------------------------------------------------------------*/ if($event == 'orderpage'){ $markup = array( 'sort' => 170, 'class_ident' => 'tips', 'label' => '
'.$markup_label. $markup_input,//html td +wrapper div 'value_formatted' => $markup_select.'
',//html /td + wrapper div 'value' => $tips_value, 'fullwidth' => true, ); } else{ $markup = array(); //only return a filled array - outside order page - if tips > 0 if(is_numeric($tips_value) && !empty($tips_value) ){ $markup = array( 'sort' => 170, 'class_ident' => 'tips', 'label' => !empty($wppizza_options['localization']['tips']) ? $wppizza_options['localization']['tips'] : '', 'value_formatted' => wppizza_format_price($tips_value), 'value' => $tips_value, 'fullwidth' => false, ); } } /* make filterable and return as array */ $markup = apply_filters( strtolower(__CLASS__ .'_'.__method__) , $markup, $event); return $markup; } } ?>