I'm trying to get the values from jQuery slider and pass them trought GET for meta search in Wordpress. Currently with my code below the input field passes this data via url: &price=Between+5000+and+25000+currency.
What is the best way for handling/getting this values so I can pass them to my php meta search function.
jQuery(function() {
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 100000,
values: [ 5000, 25000 ],
slide: function( event, ui ) {
$( "#amount" ).val( "Between " + ui.values[ 0 ] + " and " + ui.values[ 1 ] + " currency.");
}
});
$( "#amount" ).val( "Between " + $( "#slider-range" ).slider( "values", 0 ) + " and " + $( "#slider-range" ).slider( "values", 1 ) + " currency." );
});
I found a solution for myself. Still looking for better or more elegant handling of this. Here is my solution:
if( !empty($_GET['price']) ) { // Checked GET request
$pricesRange = $_GET['price'];
preg_match_all('!\d+!', $pricesRange, $matches); // Extract only the numbers
$rangeValue1 = $matches[0][0]; //preg_match_all returns multidimension array?
$rangeValue2 = $matches[0][1];
$meta_query[] = array(
'key' => 'price',
'value' => array($rangeValue1, $rangeValue2 ),
'type' => 'DECIMAL',
'compare' => 'BETWEEN',
);
}
Related
I am trying to change the order of the countries in front end - woocommerce checkout country field.
I'd like to show specific countries first.
Found some php code for it, but it doesnt seem to work to me.
Any help/guidance much appreciated
here is what i tried
add_filter( 'woocommerce_sort_countries', '__return_false' );
add_filter( 'woocommerce_countries', 'handsome_bearded_guy_add_my_country' );
add_filter( 'woocommerce_continents', 'handsome_bearded_guy_add_my_country_to_continents' );
add_filter( 'woocommerce_countries', 'wc_custom_countries_order', 10, 1 );
function handsome_bearded_guy_add_my_country( $countries ) {
$new_countries = array(
'CENTRAL' => __( 'CanaLine.gr', 'woocommerce' ),
'ToumpaSKG' => __( 'CanaLine Τούμπας (SKG)', 'woocommerce' ),
'HlioupoliSKG' => __( 'CanaLine Ηλιούπολης (SKG)', 'woocommerce' ),
'ArgiroupoliATH' => __( 'CanaLine Αργυρούπολης (ATH)', 'woocommerce' ),
'KavalaKAV' => __( 'CanaLine Καβάλας (KAV)', 'woocommerce' ),
);
return array_merge( $countries, $new_countries );
}
function handsome_bearded_guy_add_my_country_to_continents( $continents ) {
$continents['EU']['countries'][] = 'CENTRAL';
$continents['EU']['countries'][] = 'ToumpaSKG';
$continents['EU']['countries'][] = 'HlioupoliSKG';
$continents['EU']['countries'][] = 'ArgiroupoliATH';
$continents['EU']['countries'][] = 'KavalaKAV';
return $continents;
}
function wc_custom_countries_order( $countries ) {
// replace with iso code of the country (example: US or GB)
unset($countries['CENTRAL']);
unset($countries['ToumpaSKG']);
unset($countries['HlioupoliSKG']);
unset($countries['ArgiroupoliATH']);
unset($countries['KavalaKAV']);
// replace with iso code of country AND country name (example: US | United States or GB | United Kingdom (UK)
$countries = ['CENTRAL' => 'CanaLine.gr'] + ['ToumpaSKG' => 'CanaLine Τούμπας (SKG)'] + ['HlioupoliSKG' => 'CanaLine Ηλιούπολης (SKG)'] + ['ArgiroupoliATH' => 'CanaLine Αργυρούπολης (ATH)'] + ['KavalaKAV' => 'CanaLine Καβάλας (KAV)] +$countries;
return $countries;
}
Try to add higher priorities.
add_filter( 'woocommerce_sort_countries', '__return_false', 999 );
add_filter( 'woocommerce_continents', 'assign_countries_to_continent', 999 );
add_filter( 'woocommerce_countries', 'wc_custom_countries_order', 999, 1 );
function assign_countries_to_continent( $continents ) {
$continents['EU']['countries'][] = 'Country1';
$continents['EU']['countries'][] = 'Country2';
$continents['EU']['countries'][] = 'Country3';
$continents['EU']['countries'][] = 'Country4';
$continents['EU']['countries'][] = 'Country5';
return $continents;
}
function wc_custom_countries_order( $countries ) {
$countries = ['Country1' => 'Country 1'] + ['Country2' => 'Country 2'] + ['Country3' => 'Country 3'] + ['Country4' => 'Country 4'] + ['Country5' => 'Country 5'] + $countries;
return $countries;
}
Example: Total amount in words: 104.99 One hundred four and ninety-nine only. enter image description here
I will be displayed on my woocommerce checkout and in my woocommerce Email generated invoice.
Thank you
Since we are not a free coding platform, this is just a little approach. Goes into your functions.php file of your child theme. Tested and works. You still need to add the string translation for total in words and maybe a language check for the formatter output language.
/**
* Add cart totals in words to checkout
*/
add_action( 'woocommerce_review_order_after_order_total', 'woocommerce_review_order_after_order_total_action' );
function woocommerce_review_order_after_order_total_action() {
$cart_totals = WC()->cart->get_totals();
$number_formatter = new NumberFormatter( "en", NumberFormatter::SPELLOUT );
?>
<tr class="order-total-text">
<th>total in words</th>
<td><?= $number_formatter->format( $cart_totals['total'] ) ?></td>
</tr>
<?php
}
add_action( 'woocommerce_review_order_after_order_total', 'woocommerce_review_order_after_order_total_action' );
function woocommerce_review_order_after_order_total_action() {
$number = WC()->cart->get_totals();
$no = floor($number);
$point = round($number - $no, 2) * 100;
$hundred = null;
$digits_1 = strlen($no);
$i = 0;
$str = array();
$words = array('0' => '', '1' => 'one', '2' => 'two',
'3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six',
'7' => 'seven', '8' => 'eight', '9' => 'nine',
'10' => 'ten', '11' => 'eleven', '12' => 'twelve',
'13' => 'thirteen', '14' => 'fourteen',
'15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
'18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
'30' => 'thirty', '40' => 'forty', '50' => 'fifty',
'60' => 'sixty', '70' => 'seventy',
'80' => 'eighty', '90' => 'ninety');
$digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
while ($i < $digits_1) {
$divider = ($i == 2) ? 10 : 100;
$number = floor($no % $divider);
$no = floor($no / $divider);
$i += ($divider == 10) ? 1 : 2;
if ($number) {
$plural = (($counter = count($str)) && $number > 9) ? 's' : null;
$hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
$str [] = ($number < 21) ? $words[$number] .
" " . $digits[$counter] . $plural . " " . $hundred
:
$words[floor($number / 10) * 10]
. " " . $words[$number % 10] . " "
. $digits[$counter] . $plural . " " . $hundred;
} else $str[] = null;
}
$str = array_reverse($str);
$result = implode('', $str);
$points = ($point) ?
"." . $words[$point / 10] . " " .
$words[$point = $point % 10] : ''
?>
<tr class="order-total-text">
<th>Total amounts in word</th>
<td><?= $result . "Rupees " . $points . " Paise"; ?></td>
</tr>
<?php
}
I'm using this code to loop through the fields:
add_filter( 'ninja_forms_submit_data', function ( $form_data ) {
$form_model = Ninja_Forms()->form( $form_data[ 'id' ] );
foreach( $form_data[ 'fields' ] as $field ){
$field_model = $form_model->get_field( $field[ 'id' ] );
$field_key = $field_model->get_setting( 'key' );
if( 'subject_test' == $field_key ){
$field_model->update_settings( 'value', 'foo' )->save();
}
}
return $form_data;
} );
subject_test is the key of the field I'd like to change the value.
I've tried many other ways to change the value but nothing seems to work.
Can anyone point me out in the right direction?
Got it!
$form_data[ 'fields' ][ $field_id ][ 'value' ] = 'foo';
#Lee Here is the full function I used:
// Change email_admin based on subject using a hidden field
add_filter( 'ninja_forms_submit_data', function ( $form_data ) {
$form_model = Ninja_Forms()->form( $form_data[ 'id' ] );
foreach( $form_data[ 'fields' ] as $field ) { // Loop through fields
$field_model = $form_model->get_field( $field[ 'id' ] );
$field_key = $field_model->get_setting( 'key' );
$field_id = $field[ 'id' ];
if( 'subject_value' == $field_key ) {
$subject_value = '';
$subject_value = $form_data[ 'fields' ][ $field_id ][ 'value' ]; // Take subject dropdown value.
$email_redirect = get_string_between($subject_value, '{', '}'); // Get email from subject value.
$new_subject = delete_all_between($subject_value, '{', '}'); // Remove {email} from subject value.
$form_data[ 'fields' ][ $field_id ][ 'value' ] = $new_subject; // Assign new subject value.
} elseif ( 'subject_send' == $field_key ) {
if ( isset($email_redirect) )
$form_data[ 'fields' ][ $field_id ][ 'value' ] = $email_redirect; // Give hidden field the email which is used in send to field.
} else {
continue;
}
}
return $form_data;
} );
I want to get the summary of the column stay time on my grid. But I can't seem to understand or figure out how to use the summary grid in extjs. Could anyone please help me or guide me?
Here's my grid code:
Ext.ns('dlti.view.widget');
Ext.define('dlti.view.widget.PlaylistDetailsGrid' ,{
extend: 'Ext.grid.Panel',
id: 'playlist-details',
alias: 'widget.PlaylistDetailsGrid',
forceFit: true,
stripeRows: true,
selType: 'rowmodel',
autosync: true,
height: 150,
width: 950,
store: new dlti.store.PlaylistDetailsStore(),
columns: [
{
text: 'Filename',
dataIndex: 'filename',
renderer: function renderDescTarget(val, p, record) {
var desc = '';
desc = '<p style="color:#000;font-size:12px;">' + val + '</p>';
return desc;
}
},
{
text: 'Transition',
dataIndex: 'transition',
renderer: function renderDescTarget(val, p, record) {
var desc = '';
desc = '<p style="color:#000;font-size:12px;">' + val + '</p>';
return desc;
}
},
{
text: 'Stay Time',
dataIndex: 'timeframe',
renderer: function renderDescTarget(val, p, record) {
var desc = '';
desc = '<p style="color:#000;font-size:12px;">' + val + '</p>';
return desc;
}
}
]
});
You can specify summaryType and summaryRenderer like this:
summaryType: 'count',
summaryRenderer: function(value, summaryData, dataIndex) {
return ((value === 0 || value > 1) ? '(' + value + ' Tasks)' : '(1 Task)');
}
summaryType can have values like count, max, average, sum etc. and summaryRenderer is similar to the column renderer where you can give any custom logic for formatting the summary.
I have a columnrange graph and want to define the color of a single bar line. If you see the second set in the picture. depending on a certain condition I would liek to change this to different color. $schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to); if endate is not greater than today then change color to red.
How would I do this?
in view
$('#container').highcharts({
'chart':{
'type':'columnrange',
'inverted':true,
},
'exporting':{
'enabled':true
},
'title':{
'text':'Projects incomplete in 2013'
},
'xAxis':{
'categories':<?=$cat?>
},
'yAxis':{
'title':'Date',
'type':'datetime',
'dateTimeLabelFormats':{
'month':'%b'
},
'min':Date.UTC(2013,00,01)
},
'tooltip':{
formatter: function(){
return '<b>' +this.series.name + ':</b> '+ Highcharts.dateFormat('%e %b, %Y', this.point.low) + ' - ' + Highcharts.dateFormat('%e %b, %Y', this.point.high) +'<br/>' ;
}
},
'legend':{
'enabled':false
},
'series':[
{
'name':'Start - End',
'data':<?=$data?>
},
{
'name':'Forecast',
'data':<?=$schedule?>,
'color': 'green'
},
{
'name':'Actual',
'data':<?=$complete?>,
'color': 'yellow'
}
]
});
In my controller I have
public function actionGraph(){
$command = Yii::app()->db->createCommand("
SELECT
view_webprojectreport.PROJECT,
view_webprojectreport.StartDATE,
view_webprojectreport.ProjectEndDate,
view_webprojectreport.PERCENT,
view_webprojectreport.ASAAREA
FROM
view_webprojectreport
WHERE
view_webprojectreport.StartDATE >= '2013' AND
view_webprojectreport.ProjectEndDate IS NOT NULL AND
view_webprojectreport.PERCENT < 100
ORDER BY
view_webprojectreport.PERCENT DESC
")->queryAll();
$series = array();
$cat = array();
$totalLength = array();
$schedule = array();
$complete = array();
foreach ($command as $key => $model) {
$cat[] = $model['PROJECT'];
$date_from = (strtotime($model['StartDATE']) + 1*86400)*1000;
$date_to = (strtotime($model['ProjectEndDate']) + 1*86400)*1000;
$totalLength[] = array($date_from,$date_to);
$today = time();
$startdate = strtotime($model['StartDATE']);
$enddate = strtotime($model['ProjectEndDate']);
$diff_total = $enddate - $startdate;
$diff_today = $today - $startdate;
$percentage_date=round(($diff_today/$diff_total)*100,2);
$duration = ( ((strtotime($model['ProjectEndDate']) + 1*86400)*1000) - ((strtotime($model['StartDATE']) + 1*86400)*1000) );
$burn = ((time() )*1000) - ((strtotime($model['StartDATE']) + 1*86400)*1000);
$pBurned = $burn/$duration;
$time = $time = strtotime( ($date_from + $pBurned) );
//echo date('Y-m-d') . " : " . date('Y-m-d',strtotime($model['ProjectEndDate'])) . "<br>";
// place check for calculating if project end date is in past
$schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to);
$percentage_to_get = round((float)$model['PERCENT'],2);
$percentage_of_days = ((int)$model['PERCENT'] == 0)? 0 : floor($diff_total/100*$percentage_to_get);
//echo date('Y-m-d', $startdate) . " : " . date('Y-m-d', $startdate + $percentage_of_days ) . "<br>";
//echo $startdate . " : " . ($startdate + $percentage_of_days) . "<br>";
$percentComplete = (($startdate + $percentage_of_days)+ 1*86400)*1000;
$complete[] = array($date_from,$percentComplete);
}
$series = array("series"=>array(
array(
'name'=>'Start - End',
'data'=>$totalLength
),
array(
'name'=>'Forecast',
'data'=>$schedule,
'color'=> 'green'
),
array(
'name'=>'Actual',
'data'=>$complete,
'color'=> 'yellow'
)
));
print_r($series);
$this->render('graph',array(
'cat'=>json_encode($cat),
"data"=>json_encode($totalLength),
"schedule"=>json_encode($schedule),
"complete"=>json_encode($complete),
"series"=>json_encode($series)
));
}
output of schedule
[[1357689600000,1372064004000],[1360972800000,1.3686588e+12],[1359158400000,1372064004000],[1.3630464e+12,1365721200000],[1359417600000,1372064004000],[1.3709916e+12,1372064004000],[1.3686588e+12,1372064004000],[1.3681404e+12,1372064004000],[1.3699548e+12,1372064004000],[1366930800000,1372064004000]]
How would I incorporate the color in this?
$schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to);
I have found http://jsfiddle.net/Q2JMF/2/ and trying to implement but not working. graph displays nothing
My example on jsfiddle http://jsfiddle.net/shorif2000/z4HXX/2/
Your point should be object like :
{
y:10,
color: 'red'
}
So data should looks like:
data:[{
y:10,
color: 'red'
},4,5,6,7,7]
How to prepare correct structure:
http://php.net/manual/en/function.json-encode.php