# Bricks Element Condition: During Opening Hours

> Adds a "During opening hours" condition to Bricks, so a "Call us now" button or live chat block only shows while your business is open.

- Type: PHP
- Runs: Run everywhere
- Category: [Page Builders & Themes](https://wpide.com/library/category/page-builders/)
- Tags: bricks, conditions, business-hours
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/bricks-condition-opening-hours/

## Code

```php
// Opening hours per weekday (1 = Monday ... 7 = Sunday), 24-hour "HH:MM".
$wpide_bricks_hours = array(
    1 => array( '09:00', '17:30' ),
    2 => array( '09:00', '17:30' ),
    3 => array( '09:00', '17:30' ),
    4 => array( '09:00', '17:30' ),
    5 => array( '09:00', '16:00' ),
);

add_filter( 'bricks/conditions/groups', function ( $groups ) {
    foreach ( $groups as $group ) {
        if ( isset( $group['name'] ) && 'wpide' === $group['name'] ) {
            return $groups;
        }
    }

    $groups[] = array( 'name' => 'wpide', 'label' => 'Site rules' );

    return $groups;
} );

add_filter( 'bricks/conditions/options', function ( $options ) {
    $options[] = array(
        'key'     => 'wpide_open_now',
        'label'   => 'During opening hours',
        'group'   => 'wpide',
        'compare' => array(
            'type'        => 'select',
            'options'     => array( '==' => 'is', '!=' => 'is not' ),
            'placeholder' => 'is',
        ),
        'value'   => array( 'type' => 'select', 'options' => array( 'open' => 'open' ), 'placeholder' => 'open' ),
    );

    return $options;
} );

add_filter( 'bricks/conditions/result', function ( $result, $condition_key, $condition ) use ( $wpide_bricks_hours ) {
    if ( 'wpide_open_now' !== $condition_key ) {
        return $result;
    }

    $now   = new DateTime( 'now', wp_timezone() );
    $day   = (int) $now->format( 'N' );
    $time  = $now->format( 'H:i' );
    $open  = isset( $wpide_bricks_hours[ $day ] ) && $time >= $wpide_bricks_hours[ $day ][0] && $time < $wpide_bricks_hours[ $day ][1];

    return ( isset( $condition['compare'] ) && '!=' === $condition['compare'] ) ? ! $open : $open;
}, 10, 3 );
```

## Notes

Hours use the site timezone from Settings > General. Pages using it should not be cached for long.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Bricks Element Condition: During Opening Hours" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
