Time loop for WooCommerce checkout select option - wordpress

I need your help please.
I have time picker on my WordPress site, it looks like this:
woocommerce_form_field( 'time', array(
'type' => 'select',
'label' => __('Delivery Time', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => 'true',
'options' => array(
'9 AM - 10 AM' => __('9 AM - 10 AM', 'woocommerce' ),
'10 AM - 11 AM' => __('10 AM - 11 AM', 'woocommerce' ),
'11 AM - 12 PM' => __('11 AM - 12 PM', 'woocommerce' ),
'12 PM - 1 PM' => __('12 PM - 1 PM', 'woocommerce' ),
'1 PM - 2 PM' => __('1 PM - 2 PM', 'woocommerce' ),
'2 PM - 3 PM' => __('2 PM - 3 PM', 'woocommerce' ),
'3 PM - 4 PM' => __('3 PM - 4 PM', 'woocommerce' ),
'4 PM - 5 PM' => __('4 PM - 5 PM', 'woocommerce' ),
'5 PM - 6 PM' => __('5 PM - 6 PM', 'woocommerce' ),
'6 PM - 7 PM' => __('6 PM - 7 PM', 'woocommerce' ),
'7 PM - 8 PM' => __('7 PM - 8 PM', 'woocommerce' ),
'8 PM - 9 PM' => __('8 PM - 9 PM', 'woocommerce' ),
'9 PM - 10 PM' => __('9 PM - 10 PM', 'woocommerce' ),
'10 PM - 11 PM' => __('10 PM - 11 PM', 'woocommerce' ),
'11 PM - 12 AM' => __('11 PM - 12 AM', 'woocommerce' )
),
), $checkout->get_value( 'time' ));
However I want options are based on some rules:
1. If client choose todays date on date picker, no options will be avalible.
2. If client will choose tomorrows date, it will show options(Current Time + 24hours)
3. If client will choose date after tomorrow, all options will be avalible.
Please, I need your help.
Thank you.

Related

Calculate price of rental with different periods of pricing wordpress & woocommerce

Hello I'm working on a woocommerce car rental shop and I have the following issue that I'm trying to fix.
Given the following case:
A client comes to rent a car with a date period of October 29 11:00 to November 12 11:00 with a total of 15 days of rentals.
The base price of a car for rent is 17 euros/day with an extra fee of 5 euros/day for October and 17 euros/day with an extra fee of 10 euros/day for November.
So now I have the following dump that shows the same example :
Base Price: 17
Array
(
[10] => Array
(
[fee] => 5.00
[days] => 3
)
[11] => Array
(
[fee] => 10.00
[days] => 12
)
)
When I do the math I'm getting 66 euros for first period 29 October to 31 October and 324 euros for 1 November - 12 November period with a total of 390 euro.
If I were to do an average price 390 / 15 and then set that as price for the car the total would be incorrect.
How could I change the way wocommerce calculates total to calcule the price for the car + other options for rental. ?
Here is a realy basic example
$price = '17.00';
$period_range = array(
'10' => array(
'fee' => 5.00,
'days' => 3
),
'11' => array(
'fee' => 10.00,
'days' => 12
)
);
$charge = array();
foreach($period_range as $range) {
$charge[] = round($range['fee'] * $range['days']);
}
$total = array_sum($charge) + $price;
echo $total;
//this will return 152

Convert string to timestamp in symfony 4

I have a variable recover from ajax and in the controller
dd($gethour);
"Sat Oct 26 2019 00:00:04 GMT+0200 (heure d’été d’Europe centrale)"
$from = \DateTime::createFromFormat('m-d-y H:i:s', $gethour);
dd($form);
Result:false
My problem is how to convert string to timestamp seen in the base HoursPass is a type timestamp
It would be better if you could start with a real timestamp which is long number. But otherwise you could do it this way:
$gethour = "Sat Oct 26 2019 00:00:04 GMT+0200 (heure d’été d’Europe centrale)";
$chunks = explode(' ', $gethour);
$from = new \DateTime($chunks[1] . ' ' . $chunks[2] . ' ' . $chunks[3] . ' ' . $chunks[4]);
$from->setTimezone(new DateTimeZone($chunks[5]));
echo $from->format('d-m-Y H:i:s P'); // 26-10-2019 09:00:04 +02:00
you can exam this way :
date("m-d-y H:i:s", strtotime($gethour));
this way is answered for me.

WordPress | WP_Query | Get latest port from category and sub-categories

I have write a theme for WordPress and I like to have the latest posts posted in category and it's sub-categories to be displayed on top of any other post.
An example. Lets say I have the following categories:
Cat 1
Cat 1 - 1
Cat 1 - 2
Cat 1 - 2 - 1
And then I create the following posts :
Post #5 | Cat 1 - 2 | Date 2013
Post #4 | Cat 1 - 1 | Date 2012
Post #3 | Cat 1 - 2 | Date 2011
Post #2 | Cat 1 | Date 2010
Post #1 | Cat 1 - 1 - 2 | Date 2009
In the front end, when I navigate to Cat 1 I do not get as latest post the Post #5 that belong to Cat 1 - 2 where it is sub category of the Cat 1, But instead I am getting the Post #2.
Currently I am using this code :
$categoryID = get_query_var('cat');
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'category__in' => array($categoryID),
'post_status' => 'publish'
);
$eiPost = new WP_Query($args);
The problem is that this code return the latest post only from the top level category and not from the sub categories. How can I modify this code, in order to retrieve the latest posts from all the sub-categories and the top category ?
Is there any solution to this problem ?
'category__in' only displays posts from that category, not children categories.
Try using 'cat' => $categoryID insted. So your $args would be:
$args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'cat' => $categoryID,
'post_status' => 'publish'
);

kendo ui dataviz chart aggregate includes data from wrong month

I'm building a basic line chart in Kendo UI Dataviz and I'm having a problem with the aggregation method. The goal is to group my sales data by month and aggregate the Sum(Amount) which seems to work in my chart but I'm experiencing a bug that causes data from the first day of October to be included in the sum for September. Oct 2 shows in October but Oct 1 is included in September's total.
The data is:
10/1/2013 12:00:00 AM, 22964.5000
10/2/2013 12:00:00 AM, 6762.9400
Html.Kendo().Chart(Model)
.Name("revenue")
.Title("Revenue Activity by Month")
.Legend(legend => legend
.Position(ChartLegendPosition.Bottom)
)
.Series(series =>
{
series.Area(s => s.TotalRevenue, categoryExpression: model => model.Date).Aggregate(ChartSeriesAggregate.Sum).Name("Total Revenue").Color("#73c100");
series.Line(s => s.RevenueSubscriber, categoryExpression: model => model.Date).Aggregate(ChartSeriesAggregate.Sum).Name("Subscriber Revenue");
series.Line(s => s.RevenueNonSubscriber, categoryExpression: model => model.Date).Aggregate(ChartSeriesAggregate.Sum).Name("Non-Subscriber Revenue");
})
.CategoryAxis(axis => axis.Date()
.BaseUnit(ChartAxisBaseUnit.Months)
)
.ValueAxis(axis => axis
.Numeric("revenue")
.Labels(labels => labels.Format("{0:C}"))
.Line(line => line.Visible(false))
)
.Tooltip(tooltip => tooltip
.Visible(true)
.Format("{0:C}")
)
What I receive is a chart with two points on the X Axis. The first point is Sept 2013 and includes $22,964. The second point is Oct 2013 and includes $6,762.

how to change time format in rails 3.0.1

anyone can help me with this?
In my view I have:
<%= post.time %>
It displays on the screen for the row:
Sat Jan 01 17:18:00 UTC 2000
In every row it says "Sat Jan 01" + "UTC 2000"
How can I get rid of it and display only the time?
Many thanks
<%= post.date.strftime('%H:%M:%S') %>
You can read the reference for the full formatting syntax here. For example:
%S - Second of the minute (00..60)
%H - Hour of the day, 24-hour clock (00..23)
. . . and so on.
try something like this
datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"
datetime.to_s(:db) # => "2007-12-04 00:00:00"
datetime.to_s(:number) # => "20071204000000"
datetime.to_formatted_s(:short) # => "04 Dec 00:00"
datetime.to_formatted_s(:long) # => "December 04, 2007 00:00"
datetime.to_formatted_s(:long_ordinal) # => "December 4th, 2007 00:00"
datetime.to_formatted_s(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000"
also you can add your custom format like this:
# config/initializers/time_formats.rb
Time::DATE_FORMATS[:month_and_year] = "%B %Y"
Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") }

Resources