janizde/WP-Opening-Hours

Disable open_text string

Closed this issue · 2 comments

vbes commented

Hi janizde,

totally love your plugin! There is my question: using a shortcode, I don't want to show current status (like "We're currently closed"), but only todays (like "Today, you can visit us till 18.00). Is there any way, how to disable open_text and closed_text strings? When I don't use these strings in the shortcode, they're replaced by default text.

Thanks,

vbes

[op-is-open set_id="ur opening hours set id here"  show_today="always" time_format="H" today_format="Today, you can visit us till %3$s"]

I think this is what ur looking for?

Hi, sorry for the late reply. It's not possible to hide the text by default, as this is considered the primary use of this widget / shortcode, but it's interesting to see that there's also a case to just show the additional information. You can however strip it off using filters.

The easiest should be op_shortcode_attributes like so

use OpeningHours\Module\Shortcode\IsOpen;

add_filter('op_shortcode_attributes', function (array $attributes, $shortcode) {
  if ($shortcode instanceof IsOpen) {
    $attributes['text'] = '';
  }

  return $attributes;
}, 10, 2);

This will however leave you with an empty <span></span> in the markup. If you don't want this you can also filter the whole element out from the markup with op_shortcode_markup like so:

use OpeningHours\Module\Shortcode\IsOpen;

add_filter('op_shortcode_markup', function ($markup, $shortcode) {
  if ($shortcode instanceof IsOpen) {
    return preg_replace('/<span class=\"op-(?:open|closed)\">.*?<\/span>/', '', $markup);
  }

  return $markup;
}, 10, 2);