Display next delivery day based on date time rules in Woocommerce products loop










1














I have the following code below that creates a line of text under all products on the home, category and related products pages, that says "GREATER CAPE TOWN AREA"…



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;

echo '<p class="deliveryline">' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



I'd like to have a line of text above this that says "NEXT DELIVERY: " and then uses the following logic:



  • If it's a weekday BEFORE 12pm, it should say "TOMORROW"

  • If it's a weekday AFTER 12pm, it should say the name of the business day after tomorrow.

  • if it's a friday BEFORE 12pm it should say "MONDAY"

  • if it's a friday AFTER 12pm it should say "TUESDAY"

Basically, we offer next day delivery on weekdays, for orders placed before 12pm.



I have code for something similar that may work..



$now = new Zend_Date();
if (($now->get(Zend_Date::WEEKDAY_DIGIT) % 6 == 0)
|| ($now->isLater('17:00:00', Zend_Date::TIMES))
)
$now->set(
strtotime('+1 weekday', $now->toString(Zend_Date::TIMESTAMP)),
Zend_Date::TIMESTAMP
);

echo $now->toString(Zend_Date::W3C);


I just need help please figuring out the correct maths for what I need (this code is based on same day if before 5pm), and then where do I place it within the original code?



Could someone please help with this complete code snippet? Ideally I want it to look like the attached image.



Desired result:



desired result










share|improve this question























  • First I would create a custom class or function that will do this based on the criteria you input. Trying to shoehorn all that code into an action function may become problematic ..
    – Jamie_D
    Nov 12 at 14:13










  • okay.. i'm quite new at this.. so where would the function go? and how would I reference it into the original code?
    – Michelle
    Nov 12 at 14:16















1














I have the following code below that creates a line of text under all products on the home, category and related products pages, that says "GREATER CAPE TOWN AREA"…



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;

echo '<p class="deliveryline">' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



I'd like to have a line of text above this that says "NEXT DELIVERY: " and then uses the following logic:



  • If it's a weekday BEFORE 12pm, it should say "TOMORROW"

  • If it's a weekday AFTER 12pm, it should say the name of the business day after tomorrow.

  • if it's a friday BEFORE 12pm it should say "MONDAY"

  • if it's a friday AFTER 12pm it should say "TUESDAY"

Basically, we offer next day delivery on weekdays, for orders placed before 12pm.



I have code for something similar that may work..



$now = new Zend_Date();
if (($now->get(Zend_Date::WEEKDAY_DIGIT) % 6 == 0)
|| ($now->isLater('17:00:00', Zend_Date::TIMES))
)
$now->set(
strtotime('+1 weekday', $now->toString(Zend_Date::TIMESTAMP)),
Zend_Date::TIMESTAMP
);

echo $now->toString(Zend_Date::W3C);


I just need help please figuring out the correct maths for what I need (this code is based on same day if before 5pm), and then where do I place it within the original code?



Could someone please help with this complete code snippet? Ideally I want it to look like the attached image.



Desired result:



desired result










share|improve this question























  • First I would create a custom class or function that will do this based on the criteria you input. Trying to shoehorn all that code into an action function may become problematic ..
    – Jamie_D
    Nov 12 at 14:13










  • okay.. i'm quite new at this.. so where would the function go? and how would I reference it into the original code?
    – Michelle
    Nov 12 at 14:16













1












1








1







I have the following code below that creates a line of text under all products on the home, category and related products pages, that says "GREATER CAPE TOWN AREA"…



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;

echo '<p class="deliveryline">' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



I'd like to have a line of text above this that says "NEXT DELIVERY: " and then uses the following logic:



  • If it's a weekday BEFORE 12pm, it should say "TOMORROW"

  • If it's a weekday AFTER 12pm, it should say the name of the business day after tomorrow.

  • if it's a friday BEFORE 12pm it should say "MONDAY"

  • if it's a friday AFTER 12pm it should say "TUESDAY"

Basically, we offer next day delivery on weekdays, for orders placed before 12pm.



I have code for something similar that may work..



$now = new Zend_Date();
if (($now->get(Zend_Date::WEEKDAY_DIGIT) % 6 == 0)
|| ($now->isLater('17:00:00', Zend_Date::TIMES))
)
$now->set(
strtotime('+1 weekday', $now->toString(Zend_Date::TIMESTAMP)),
Zend_Date::TIMESTAMP
);

echo $now->toString(Zend_Date::W3C);


I just need help please figuring out the correct maths for what I need (this code is based on same day if before 5pm), and then where do I place it within the original code?



Could someone please help with this complete code snippet? Ideally I want it to look like the attached image.



Desired result:



desired result










share|improve this question















I have the following code below that creates a line of text under all products on the home, category and related products pages, that says "GREATER CAPE TOWN AREA"…



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop()
global $product;

echo '<p class="deliveryline">' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



I'd like to have a line of text above this that says "NEXT DELIVERY: " and then uses the following logic:



  • If it's a weekday BEFORE 12pm, it should say "TOMORROW"

  • If it's a weekday AFTER 12pm, it should say the name of the business day after tomorrow.

  • if it's a friday BEFORE 12pm it should say "MONDAY"

  • if it's a friday AFTER 12pm it should say "TUESDAY"

Basically, we offer next day delivery on weekdays, for orders placed before 12pm.



I have code for something similar that may work..



$now = new Zend_Date();
if (($now->get(Zend_Date::WEEKDAY_DIGIT) % 6 == 0)
|| ($now->isLater('17:00:00', Zend_Date::TIMES))
)
$now->set(
strtotime('+1 weekday', $now->toString(Zend_Date::TIMESTAMP)),
Zend_Date::TIMESTAMP
);

echo $now->toString(Zend_Date::W3C);


I just need help please figuring out the correct maths for what I need (this code is based on same day if before 5pm), and then where do I place it within the original code?



Could someone please help with this complete code snippet? Ideally I want it to look like the attached image.



Desired result:



desired result







php wordpress date woocommerce product






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 14:54









LoicTheAztec

84.1k126095




84.1k126095










asked Nov 12 at 12:48









Michelle

597




597











  • First I would create a custom class or function that will do this based on the criteria you input. Trying to shoehorn all that code into an action function may become problematic ..
    – Jamie_D
    Nov 12 at 14:13










  • okay.. i'm quite new at this.. so where would the function go? and how would I reference it into the original code?
    – Michelle
    Nov 12 at 14:16
















  • First I would create a custom class or function that will do this based on the criteria you input. Trying to shoehorn all that code into an action function may become problematic ..
    – Jamie_D
    Nov 12 at 14:13










  • okay.. i'm quite new at this.. so where would the function go? and how would I reference it into the original code?
    – Michelle
    Nov 12 at 14:16















First I would create a custom class or function that will do this based on the criteria you input. Trying to shoehorn all that code into an action function may become problematic ..
– Jamie_D
Nov 12 at 14:13




First I would create a custom class or function that will do this based on the criteria you input. Trying to shoehorn all that code into an action function may become problematic ..
– Jamie_D
Nov 12 at 14:13












okay.. i'm quite new at this.. so where would the function go? and how would I reference it into the original code?
– Michelle
Nov 12 at 14:16




okay.. i'm quite new at this.. so where would the function go? and how would I reference it into the original code?
– Michelle
Nov 12 at 14:16












1 Answer
1






active

oldest

votes


















1














The following code will display dynamically the delivery day based on your time and dates specifications (You will have to set your shop time zone in the code):



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop() $is_week_end )
$$displayed_day = __("THUESDAY", "woocommerce");


// Dynamic text Output based on date and time
echo '<p class="deliveryline">' . __("NEXT DELIVERY: ", "woocommerce") . $displayed_day .
'<br>' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



Code goes in function.php file of your active child theme (active theme). Tested and works.



enter image description here






share|improve this answer






















  • thanks! i'm trying to put this in but every time i try and update a php file (any of them) I get this message - Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP. Do you know why??
    – Michelle
    Nov 13 at 7:59










  • okay i added it manually to the function.php file and it works perfectly! Thanks so much... I still have no idea why i can't use the editor today.. it worked perfectly yesterday
    – Michelle
    Nov 13 at 8:25










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262537%2fdisplay-next-delivery-day-based-on-date-time-rules-in-woocommerce-products-loop%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The following code will display dynamically the delivery day based on your time and dates specifications (You will have to set your shop time zone in the code):



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop() $is_week_end )
$$displayed_day = __("THUESDAY", "woocommerce");


// Dynamic text Output based on date and time
echo '<p class="deliveryline">' . __("NEXT DELIVERY: ", "woocommerce") . $displayed_day .
'<br>' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



Code goes in function.php file of your active child theme (active theme). Tested and works.



enter image description here






share|improve this answer






















  • thanks! i'm trying to put this in but every time i try and update a php file (any of them) I get this message - Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP. Do you know why??
    – Michelle
    Nov 13 at 7:59










  • okay i added it manually to the function.php file and it works perfectly! Thanks so much... I still have no idea why i can't use the editor today.. it worked perfectly yesterday
    – Michelle
    Nov 13 at 8:25















1














The following code will display dynamically the delivery day based on your time and dates specifications (You will have to set your shop time zone in the code):



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop() $is_week_end )
$$displayed_day = __("THUESDAY", "woocommerce");


// Dynamic text Output based on date and time
echo '<p class="deliveryline">' . __("NEXT DELIVERY: ", "woocommerce") . $displayed_day .
'<br>' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



Code goes in function.php file of your active child theme (active theme). Tested and works.



enter image description here






share|improve this answer






















  • thanks! i'm trying to put this in but every time i try and update a php file (any of them) I get this message - Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP. Do you know why??
    – Michelle
    Nov 13 at 7:59










  • okay i added it manually to the function.php file and it works perfectly! Thanks so much... I still have no idea why i can't use the editor today.. it worked perfectly yesterday
    – Michelle
    Nov 13 at 8:25













1












1








1






The following code will display dynamically the delivery day based on your time and dates specifications (You will have to set your shop time zone in the code):



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop() $is_week_end )
$$displayed_day = __("THUESDAY", "woocommerce");


// Dynamic text Output based on date and time
echo '<p class="deliveryline">' . __("NEXT DELIVERY: ", "woocommerce") . $displayed_day .
'<br>' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



Code goes in function.php file of your active child theme (active theme). Tested and works.



enter image description here






share|improve this answer














The following code will display dynamically the delivery day based on your time and dates specifications (You will have to set your shop time zone in the code):



add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_products_loop', 20 );
function woocommerce_products_loop() $is_week_end )
$$displayed_day = __("THUESDAY", "woocommerce");


// Dynamic text Output based on date and time
echo '<p class="deliveryline">' . __("NEXT DELIVERY: ", "woocommerce") . $displayed_day .
'<br>' . __("GREATER CAPE TOWN AREA", "woocommerce") . '</p>';



Code goes in function.php file of your active child theme (active theme). Tested and works.



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 14:57

























answered Nov 12 at 14:50









LoicTheAztec

84.1k126095




84.1k126095











  • thanks! i'm trying to put this in but every time i try and update a php file (any of them) I get this message - Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP. Do you know why??
    – Michelle
    Nov 13 at 7:59










  • okay i added it manually to the function.php file and it works perfectly! Thanks so much... I still have no idea why i can't use the editor today.. it worked perfectly yesterday
    – Michelle
    Nov 13 at 8:25
















  • thanks! i'm trying to put this in but every time i try and update a php file (any of them) I get this message - Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP. Do you know why??
    – Michelle
    Nov 13 at 7:59










  • okay i added it manually to the function.php file and it works perfectly! Thanks so much... I still have no idea why i can't use the editor today.. it worked perfectly yesterday
    – Michelle
    Nov 13 at 8:25















thanks! i'm trying to put this in but every time i try and update a php file (any of them) I get this message - Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP. Do you know why??
– Michelle
Nov 13 at 7:59




thanks! i'm trying to put this in but every time i try and update a php file (any of them) I get this message - Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP. Do you know why??
– Michelle
Nov 13 at 7:59












okay i added it manually to the function.php file and it works perfectly! Thanks so much... I still have no idea why i can't use the editor today.. it worked perfectly yesterday
– Michelle
Nov 13 at 8:25




okay i added it manually to the function.php file and it works perfectly! Thanks so much... I still have no idea why i can't use the editor today.. it worked perfectly yesterday
– Michelle
Nov 13 at 8:25

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262537%2fdisplay-next-delivery-day-based-on-date-time-rules-in-woocommerce-products-loop%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線