Skip Navigation

[Résolu] business hours

This support ticket is created Il y a 2 années et 10 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 12 réponses, has 2 voix.

Last updated by Waqar Il y a 2 années et 9 mois.

Assisted by: Waqar.

Auteur
Publications
#2081049

I've got a php snippet that adds days of the week and business hours to a CPT.

How can I make it work with another CPT?

p.s. - I don't use Blocks.

#2081281

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

Can you please share temporary admin login details along with the information on where this custom code snippet can be seen?

I'll be in a better position to guide you with the next steps, accordingly.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#2088509

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for sharing the admin access.

In your custom code snippet, you'll see this code at line# 12:


$allowed_post_types = array("restaurant, stay, essentials");

At the moment this code is set to execute for these 3 post types "restaurant", "stay", and "stay".

To make it execute for more post types, you can add their slugs in the same comma-separated list.

For example:


$allowed_post_types = array("restaurant, stay, essentials, books, shops");

#2088983

Hi, Waqar, and thank you. Still nothing happening over here. I've added the slug as instructed.

I've got it set up as a view and don't understand how to add the other post types to the view.

Sorry. Can you help? The view is called 'Restaurant Hours Block'.

I suppose it has something to do with Repeatable Field Groups?

#2092095

Hi, Waqar, are you still here?

#2092233

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Thank you for waiting and I apologize for the delay in getting back on this.

I found the original thread where Minesh shared this custom code:
https://toolset.com/forums/topic/prepopulate-fields-in-nested-repeatable-fields-view/#post-1240789

That code is specifically designed to work with the "Restaurants" post type, with which an "Operating Hours" repeatable field group has been created.

Currently, a custom field group named "Hours" exists for the "Restaurants" post type.
( yourwebsite.com/wp-admin/admin.php?page=wpcf-edit&group_id=6924 )

To make this pre-population custom code also work for other post types, you'll need to make sure that a custom field group similar to "Hours" with repeatable field group and fields is also added for those other post types as well.

Once you've created a custom field group like this for all the other post types too, please share their details and I'll share some pointers on what changes are needed in the custom code accordingly.

#2092899

Thanks, Waqar! I'm working on it, will let you know!

#2094121

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update and I'll wait to hear back from you.

#2097389

Replying to a Toolset email, still working on it.

#2097391

Responding to Toolset nag email, still working on it!

#2098861

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

Please take your time and you don't have to reply to each reminder email.

Even if you have a follow-up question after this ticket has closed, you can start a new one and include this ticket's link in it and we'll have the background information.

#2101493

Hi, Waqar, I'm back. I need step-by-step instructions to get this done.

I've tried but have gotten as far as to crash my site.

Thanks.

#2102851

Waqar
Supporter

Languages: Anglais (English )

Timezone: Asia/Karachi (GMT+05:00)

I'd be happy to assist you with more specific steps, but I'll need to understand first, what led to the crash.

After exactly which action did the website crashed and did you see any error or warning when it happened?

Thinking it through, is there any specific reason you're using a repeatable field group for storing opening and closing hours for the days of the week?

The challenge with a repeatable field group is that it can only be used with one post type. But you need to store the opening and closing hours for more than one post type. Moreover, the repeatable field groups are beneficial for the cases where the number of data entries is infinite or variable. But, in this case, the days of the weeks will always remain 7.
(you'll need to store 7 records of opening and closing hours for each post)

Based on this, I'll recommend adding a new field group and name it something like "Operating Hours" and set it to show for all the post types where you need to store the opening and closing hours.

Next, in this field group, you can add these 14 single line type custom fields:

- Opening Hour Monday
- Closing Hour Monday
- Opening Hour Tuesday
- Closing Hour Tuesday
- Opening Hour Wednesday
- Closing Hour Wednesday
- Opening Hour Thursday
- Closing Hour Thursday
- Opening Hour Friday
- Closing Hour Friday
- Opening Hour Saturday
- Closing Hour Saturday
- Opening Hour Sunday
- Closing Hour Sunday

This approach will be efficient because:

a). to add the opening and closing hours with each post, you won't need to create entries inside the repeatable field group
b). you won't need the custom code from Minesh to automatically create the repeatable field group entries
c). you won't have to create separate Hours custom field groups with separate repeatable field groups with separate opening and closing hours fields, for each post type.
d). to show the custom field values from the repeatable field group, you need to use a post view. But to show the custom fields added directly to the post type (i.e. without the repeatable field group), you can show them directly like regular custom fields, without a post view.

I hope this helps and please let me know if you have any questions.

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