Search code examples
wordpresswoocommerceadvanced-custom-fieldscategoriescustom-fields

Woocommerce: Customizing the availability of a category


I have many products nested within parent categories in WooCommerce. I want to be able to apply a custom field where I can specify a time availability for categories as a admin feature only in Back end.

Theory:

  1. Back end - On each parent category I will have this custom field where I can type or choose a time frame: for example 11:00-17:00.
  2. Front end:
  • During this time frame, users will be able to browse all the products within that category.
  • Outside of this time frame all the products within that category will stay visible (but inactive) and they will be displayed greyed out or with a 'closed' banner (something like that).

Where can I start with this?


Solution

  • THE BEGINNING

    You can start adding 2 plugins to add a custom time picker on product categories admin pages:

    This is just he beginning (and I can't confirm that is the best way). So In ACF you create a group and you name it:

    create a group

    Then you set the location (It's going to be a "taxonomy term" for "Product categories"):

    location

    Then In options you can chose it like a Metabox on the side (on backend):

    Metabox on side

    After you add a new field and name it. You chose the field type and time only option:

    Field type [Field type option8

    Then now you are going to compile all the other options to fit your needs. Then you can save and add, if you need a 2nd field…

    Now if you go to the WooCommerce Products Menu, under categories submenu, you will get this:

    The custom field in action under product categories

    Now you can read a little the ACF documentation and also the wooThemes/woocommerce dev. documentation too.

    You can customize WooCommerce overriding the templates and use hook filter and actions.

    You will find in here on Stack OverFlow and over internet a lot of code, examples and tutorials, to begin and try to achieve your project. When needed you will post questions to get helped, with the code you are using telling what is working and what not…