Ecommerce software home
Shopping Cart Software Forum for Ecommerce Templates
 
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

Find us on Facebook Follow us on Twitter View our YouTube channel
Search our site
 All Forums
 Technical
 PHP (Unix / Linux / Apache) versions
 Content Manager sections that can expire?
Author « Topic »  

Fingertech
Advanced Member

Canada
317 Posts

Posted - 07/21/2022 :  13:42:06  
Is there some code snippet that can make <p>, <div>, whatever, expire on a certain date?
For example, putting a block of text saying we will be closed X->Y, which won't stick around weeks after I've forgotten to change it. :P

1818charlie
ECT Moderator

United Kingdom
1180 Posts

Posted - 07/21/2022 :  15:16:27  
Hi Kurtis

Using PHP to Dynamically Hide Content after an Expiration Date

This may be a place to start https://www.cyberscorpion.com/2011-06/using-php-to-dynamically-hide-content-after-an-expiration-date/

Steve
Manchester UK

"Anything in life that is worth doing is worth overdoing, moderation is for cowards"

Fingertech
Advanced Member

Canada
317 Posts

Posted - 07/25/2022 :  17:20:16  
That works beautifully for the hard-coded pages, thanks.
Is there a way to use <?php> inside the content manager / product pages?

1818charlie
ECT Moderator

United Kingdom
1180 Posts

Posted - 07/25/2022 :  17:54:09  
Hi Kurtis

quote:
Is there a way to use <?php> inside the content manager / product pages?

I can't say & I think the best man to answer that one will be Vince.

Steve
Manchester UK

"Anything in life that is worth doing is worth overdoing, moderation is for cowards"

dbdave
ECT Moderator

USA
10286 Posts

Posted - 07/25/2022 :  19:11:33  
There are lot's of examples for doing this with javascript. Check that out, because you can use javascript in content regions.

My suggestion would be to assign a class to the content you want to hide/show and based on the date, the class is set to display (or not).

David

Fingertech
Advanced Member

Canada
317 Posts

Posted - 08/03/2022 :  12:50:26  
Thanks Dave. I attempted a few things, but was unsuccessful. I'm not familiar enough with javascript to really know what I'm doing.
I tried the answer from this page: https://stackoverflow.com/questions/51739147/how-to-expire-div-on-specific-day
It might just be the syntax that I'm getting wrong, as the top
$(function() {
can't be written as-is, so I wrapped it in a
<script type="text/javascript" language="javascript"> ... </script>
but nope.

ITZAP
Ecommerce Template Guru

Australia
1010 Posts

Posted - 08/03/2022 :  18:01:39  
Joomla contains an option to set "Start Publishing" and "Finish Publishing" date and time.



More details: Scheduling an Article to be available only between certain dates >>

Also dotCMS: Setting Publish and Expire Dates for Content >>

And there is a plug-in named PublishPress: How to Automatically Expire Posts, Pages, and Products in WordPress (this page contains code examples)

Certainly a very handy feature.

Gary

Edited by - ITZAP on 08/03/2022 18:22:49

dbdave
ECT Moderator

USA
10286 Posts

Posted - 08/03/2022 :  18:12:47  
The example on that page is jquery. Perhaps you are not running jquery on the page.

You can view the fiddle here for the 2nd post on that page - https://jsfiddle.net/xpvt214o/569177/
In the upper left panel where the dates are there in the html, change the year to 2022 on one of them, then run (click run) and you will see that div appear.

This is proof is works and all of the code is there.

This is your html example (change the date to your desired date and be sure to keep that same format.
<div class="with-expiry" style="display:none" data-expiry="August 07, 2018 12:00:00">
<p>Your content here</p>
</div>


Place this jquery function at first part of the page after the opening <body> tag
$(function() {

var current_date = new Date();

$(".with-expiry").each(function() {
var div_date = $(this).data('expiry');

// wrap in Date class
div_date = new Date(div_date);

if(current_date.getTime()>div_date.getTime()){
$(this).hide();
} else {
$(this).show();
}
});



})


Open the page and see if it's working as expected. If not, view source and use find to search for the word jquery
If it's not found, then the easy thing to do is add this to the <head> section of the page -
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


If it's not working, message me a link to the page and I'll tell you why.

Thanks,
David

Edited by - dbdave on 08/03/2022 18:14:39

1818charlie
ECT Moderator

United Kingdom
1180 Posts

Posted - 08/03/2022 :  18:25:51  
Having seen Garys post regarding the Joomla feature has made me think about the start & end date feature within the ECT admin for Discount Coupon feature.

I've no understanding of the mechanics of how that works apart from the feature requiring to know the time & date. Is that feature able to be repurposed towards products & articles whereby a store owner could set a start & end time?

Just a thought & I suppose possibly only Vince may have an answer/idea about this.

Steve
Manchester UK

"Anything in life that is worth doing is worth overdoing, moderation is for cowards"

Fingertech
Advanced Member

Canada
317 Posts

Posted - 08/04/2022 :  12:59:16  
Hi Dave, I've added it to my index for the Front Page Notices content management section: https://www.fingertechrobotics.com/index.php
Everything is there in the page source but the script isn't showing/hiding the divs. I've got two divs above the red Shipping Notice - one that should be expired, and one that should be showing.

There was already
/jquery/1.8.2/jquery.min.js
but I made it
/jquery/1.11.1/jquery.min.js
to match the example. No change. (Any reason to keep the older version instead of the new?)

Also, when refreshing the front page, you can see the bit of function() text appear at the top then disappear quickly. I assume that's not supposed to show ever?

dbdave
ECT Moderator

USA
10286 Posts

Posted - 08/04/2022 :  13:36:49  
So sorry... Wrap the code in script tags like so

<script>
$(function() {

var current_date = new Date();

$(".with-expiry").each(function() {
var div_date = $(this).data('expiry');

// wrap in Date class
div_date = new Date(div_date);

if(current_date.getTime()>div_date.getTime()){
$(this).hide();
} else {
$(this).show();
}
});



})</script>

Edited by - dbdave on 08/04/2022 13:42:19

Fingertech
Advanced Member

Canada
317 Posts

Posted - 08/08/2022 :  10:22:23  
Yeah that worked great! Now I can write anything anywhere and have it expire on a certain date.

Along those lines, is there a way to call a Content Region into the cart.php checkout page? (I would love to slide it into $xxChkCmp, so both my front page and shipping selection page both display the store-closure dates and I don't have to write it repeatedly.)

dbdave
ECT Moderator

USA
10286 Posts

Posted - 08/08/2022 :  11:22:20  
Have you tested changing the output of $xxChkCmp to a content region?
It may work as both are server side code.

David

Fingertech
Advanced Member

Canada
317 Posts

Posted - 08/09/2022 :  14:02:38  
How would that look? Tried this but doesn't show anything:

$xxChkCmp='<?php $regionid=19; ?><?php include "vsadmin/inc/inccontentregion.php" ?>';



Checking source it turns it into this:
<!--?php $regionid=19; ?-->
<!--?php include "vsadmin/inc/inccontentregion.php" ?-->

dbdave
ECT Moderator

USA
10286 Posts

Posted - 08/09/2022 :  16:43:27  
Keep in mind this may throw errors on your site, so be prepared to reverse the changes, but the single quotes there are saying this is a string of text ( https://www.php.net/manual/en/language.types.string.php ).
You might try it with double quotes, like so ( https://www.codecademy.com/learn/learn-php/modules/learn-php-variables ).

$xxChkCmp="<?php $regionid=19; ?><?php include "vsadmin/inc/inccontentregion.php" ?>";

If Vince sees this post, perhaps he will comment as he would likely know if it's possible and if so, how to format the languagefile entry.

Thanks,
David

Fingertech
Advanced Member

Canada
317 Posts

Posted - 08/10/2022 :  11:00:38  
I changed
$xxChkCmp='<?php $regionid=19; ?><?php include "vsadmin/inc/inccontentregion.php" ?>';

to
$xxChkCmp="<?php $regionid=19; ?><?php include 'vsadmin/inc/inccontentregion.php' ?>";

but no luck. Once again source shows:
<!--?php $regionid=19; ?-->
<!--?php include "vsadmin/inc/inccontentregion.php" ?-->

dbdave
ECT Moderator

USA
10286 Posts

Posted - 08/10/2022 :  12:10:10  
It's probably not possible to use a content region there.
Why not create a div in the cart.php page just above the include line that calls up the cart and add the content region there?

Thanks,
David
  « Topic »  
Jump To:
Shopping Cart Software Forum for Ecommerce Templates © 2002-2022 ecommercetemplates.com
This page was generated in 0.05 seconds. Snitz Forums 2000