Skip Navigation

[Gelöst] Display timed content

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created vor 6 Jahre, 3 Monate. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 Antworten, has 2 Stimmen.

Last updated by Christian Cox vor 6 Jahre, 3 Monate.

Assisted by: Christian Cox.

Author
Artikel
#596241
Screen Shot 2017-12-06 at 6.01.12 PM.png

I am trying to: Only display a view if a woocommerce purchase was made after 24 hours. If a user purchased within the last 24 hours, then display a message instead

Link to a page where the issue can be seen:
You will need login privileges

I expected to see:
To see a woocommerce product available as the purchase was done 3 days ago

Instead, I got: A message saying I cannot buy because I bought less than 24 hours agp

Setup:
Content Selection: Orders
Order by post date.
Limit 1
Query Filter: Date Condition
Select Posts with 'published date' 'between those'
Hour: current one
past one: 24 hours

Custom field filter: _customer_user
Use shortcode attribute: userid

Check status: wc-pending, wc-processing, wc-completed

View

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop>
      <div class="alert alert-danger" role="alert">
		You already placed an order today. You can order again in 24 hours. See you then!
      </div>
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		[wpv-view name="woocommerce-items"]
	[/wpv-no-items-found]
[wpv-layout-end]
#596370

Hi, I see that this View is included in the Content Template "Check Order", but I'm not clear how to see it on the front-end of your site. Is it currently anywhere visible? Also, can you provide login credentials for a User with a recent purchase, or is it okay for me to create a test User and test purchase? Private reply enabled again.

#597431
#597540

Actually I am wonering if I have the above correct? How does Woocommerce display the order date? Above I assumed it may be the post date, but now I am wondering if it uses a custom field for this, but I cannot find which field this may be. Already looked under Hidden custom fields but there is nothing indicating an Order Date there.

#597744

I think the problem with the View as it is set up now is that it's only checking the hour of publication without considering the date as well - so the filter isn't behaving as expected. Rather than try to build this type of query in Views, I think you'll have more precise results using a code-based date query. Try this:

  • Delete the date filter from your View
  • In your child theme's functions.php file, add the following code:
    add_filter( 'wpv_filter_query', 'featured_products', 99, 3 );
    function featured_products( $query_args,$views_settings, $view_id) {
      if ($view_id == 12345){
        $query_args['date_query'] = array(
          array(
            'after' => '24 hours ago'
          ),
        );
      }
      return $query_args;
    }
  • Replace 12345 with the numeric ID of this View
  • #597974

    And then how do I display the view? Do I leave it all intact as it is right now but simply disable the date field? Also, this must be the the current logged in user only (who has made the purchase). I will test this soon as we are moving servers now, but please let me know 🙂 Thanks buddy.

    #599595

    And then how do I display the view? Do I leave it all intact as it is right now but simply disable the date field?
    Delete the Post Date filter from your Query Filter, leave the other filters in place, and place the View just like you would normally place it in your post or template.

    Also, this must be the the current logged in user only (who has made the purchase).
    Assuming you are passing "userid" into the shortcode correctly, this should work. The filter changes we implemented in PHP will extend the user ID filter you have applied in the View editor, not replace them.

    Das Forum „Types Community Support“ ist für neue Themen und Antworten geschlossen.

    This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.