Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

"Order before" countdown using a widget and Widget Logic WordPress

  • SOLVED

Hello,

Using the [[LINK href="https://wordpress.org/plugins/recurring-timer-widget/"]]Recurring Timer Widget[[/LINK]] and [[LINK href="https://wordpress.org/plugins/widget-logic/"]]Widget Logic[[/LINK]] I would like to create a notice on a website running WooCommerce, to inform customers that if they order before a given time, they can get their order the next day.

I haven't been able to find any plugin that offers this functionality for WooCommerce yet, so I am trying to do my own here.

Basically the shop ships at the same time on all weekdays, which is 4 PM.

On Saturdays it's at noon and on Sundays there is no shipping.

So using multiple Recurring Timer Widgets and the proper PHP in Widget Logic, it should be possible to create these 3 different scenarios.

What I have today is the following setup which "only works" from Monday to Friday, or is accurate so to speak. [[LINK href="https://www.dropbox.com/s/3g4vpnjocs6utkh/wp-admin-setup.png?dl=0"]]Please see this screenshot[[/LINK]].

That turns into [[LINK href="https://www.dropbox.com/s/jtu7w2ikoxopkwo/preview.png?dl=0"]]the following widget in the sidebar[[/LINK]] which is then displayed from Monday to Friday.

So, ultimately I would like to have the proper strtotime formats put into both the Recurring Timer Widget itself, and Widget Logic.

Shipping time table:
Monday - Friday: 4PM
Saturday: Noon
Sunday: No shipping

I hope this task is clear enough. Can someone help me with that?

Answers (3)

2015-01-18

Dbranes answers:

Hi, what about using three instances of the Recurring Timer widget with the following <em>widget logic</em>:

<strong>Widget #1: Monday - Friday 16:00 </strong>
date( 'N' ) <= 4
|| date( 'N' ) == 5 && time() < strtotime( "16:00" )


<strong>Widget #2: Friday 16:00 - Saturday 12:00 </strong>
date( 'N' ) == 5 && time() >= strtotime( "16:00" )
|| date( 'N' ) == 6 && time() < strtotime( "12:00" )


<strong>Widget #3: Saturday 12:00 - Sunday </strong>
date( 'N' ) == 6 && time() >= strtotime( "12:00" )
|| date( 'N' ) == 7



cruiseback comments:

Hey Dbranes,

This is exactly what I had in mind.

However when I test with your 3 widgets using the above syntax in Widget Logic, right now, I don't see any of them on the frontpage.
The idea should be that one of them should always be visible.

[[LINK href="http://www.timeanddate.com/worldclock/denmark/copenhagen"]]The time in Copenhagen, Denmark right now[[/LINK]], for reference.


Dbranes comments:

ok, Did you use the latest update?

Seems to work on my install, I get the <strong>Widget #2: Weekend before Sunday Noon</strong> showing up only.

Note that time() and date() are using the server time.


cruiseback comments:

Ah, right, now it works.. no I pasted one of your previous edits.

You have put Sunday into both

#2
date( 'N' ) == 6 || ( date( 'N' ) == 7 && time() < strtotime( "this sunday 12:00" ) )

and

#3
date( 'N' ) == 7 && ( time() >= strtotime( "this sunday 12:00" ) )

is that deliberately?


Dbranes comments:

ok great,

aha, this setup is for a delivery on Sunday noon and nothing on Saturday,

But I see that it should be the otherway around ;-)

Let me try to update that ;-)


cruiseback comments:

Right ok, no worries :)

Another thing though, I would also like your help on setting up the widgets themselves (beside Widget Logic).

This is giving me an enormous headache to wrap my mind around, but basically I think that I need more than one widget for Saturday(?)

Your widget #2 right now says that if it's a Saturday, and if the time is before 12 noon, then show that, but then what about when the time passes 12 noon?

Then the sidebar should inform the customer that the next shipment will be on Monday at 16PM.


Dbranes comments:

I updated the widget logic.

I could take a look at the Widgets themselves, but it's getting late here at the Reykjavik timezone,

so we could check it out tomorrow.


cruiseback comments:

That would be totally fine with me. Have a good nights sleep.

2015-01-18

Hariprasad Vijayan answers:

Hello,

Here is one thought

1. Register couple of sidebars using [[LINK href="http://codex.wordpress.org/Function_Reference/register_sidebar"]]http://codex.wordpress.org/Function_Reference/register_sidebar[[/LINK]] ( one is for Saturday and another is for Sunday. You already have one, you can keep that for Weekdays)
2. Add Recurring Timer Widget from dashboard to corresponding widget area. (For Saturday and Sunday)
3. Write condition based on day of the week in your template file(am not sure which file that it is, may be sidebar.php?)

$dw = date( "w");
if($dw < 6)
{
// Use your current code for calling dynamic sidebar here.
}
else if($dw == 6)
{
// Call dynamic sidebar created for Saturday
}
else if($dw == 7)
{
// Call dynamic sidebar created for Sunday
}


does that make sense?

Regards,
Hariprasad


cruiseback comments:

This makes sense yes, but it's not really an answer to my question.

2015-01-18

Romel Apuya answers:

Hi,

You can use dynamic widgets instead??
[[LINK href="https://wordpress.org/plugins/dynamic-widgets/"]]https://wordpress.org/plugins/dynamic-widgets/[[/LINK]]

and do this settings..

make two recurring widgets and a text widget
and add this
[[LINK href="https://www.dropbox.com/sh/gpdcjh6428guye5/AAAdxKNHqmtw89MlZsVl971ta?dl=0"]]
https://www.dropbox.com/sh/gpdcjh6428guye5/AAAdxKNHqmtw89MlZsVl971ta?dl=0[[/LINK]]