How to Get Week Days List in Magento 2 System Configuration
Magento 2 admin panel offers multiple input types such as text box, radio button, dropdown, multi-select boxes, etc. The input values of these fields are stored and displayed in different forms of grids, forms, fields, images, etc.
Sometimes, while developing Magento 2 extensions, or custom features, developers often need to provide an option to choose days of the week to exclude or include in the module’s functionalities.
For example, the feature for the admin to select the days of the week when a customer can book an appointment, or select the days on which the store will offer delivery.
Even when you want the store admin to monitor the days off as per the business requirements, the above solution is helpful.
In all these cases, you need to get week days list in Magento 2 system configuration as shown below:
If you face a similar requirement, feel free to use the below solution:
Method to Get Week Days List in Magento 2 System Configuration
Use the below code in the system.xml at app/code/Meetanshi/CustomerAppointment/etc/adminhtml
1 2 3 4 |
<field id="week_days" translate="label" type="multiselect" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Week day</label> <source_model>Magento\Config\Model\Config\Source\Locale\Weekdays</source_model> </field> |
Simple. Isn’t it?
That’s it to get the weekdays list in Magento 2 system configuration. You extensions can work expectedly if certain configurations are made to have particular values. For that you will need magento 2 set default config value.
Any doubts can be mentioned in the Comments section below and I’d be happy to help!
Do share the solution with fellow developers via social media.
Thanks.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Add Custom Field Below Apply Discount Code in Magento 2 Cart Page
Top 6 Experts’ Strategies for Application of Artificial Intelligence in E-commerce [2022]
Next