• Resolved ElectricFeet

    (@electricfeet)


    Further to my previous question about formatting opening times horizontally, I went down the template route and modified the template.

    I added the call to my modified template in my child theme’s functions.php with:

    add_filter('op_shortcode_template', 'specify_different_template', 10, 2);
    function specify_different_template( $template, $shortcode ) {
    
        return '../../../themes/my-child-theme/wp-opening-hours/orari.php';
    }

    It works great for the op-overview shortcode.

    Unfortunately, the code above seems to be forcing the same template for the is-open shortcode. This gives a fatal error if I add an is-open shortcode. Specifically, I get:
    Fatal error: Uncaught Error: Call to a member function getDescription() on null in /...path-to-my-wordpress.../wp-content/themes/my-child-theme/wp-opening-hours/orari.php:29 Stack trace: #0 /...path-to-my-wordpress.../wp-content/plugins/wp-opening-hours/classes/OpeningHours/Util/ViewRenderer.php(35): include() #1 /...path-to-my-wordpress.../wp-content/plugins/wp-opening-hours/classes/OpeningHours/Util/ViewRenderer.php(44): OpeningHours\Util\ViewRenderer->render() #2 /...path-to-my-wordpress.../wp-content/plugins/wp-opening-hours/classes/OpeningHours/Module/Shortcode/AbstractShortcode.php(145): OpeningHours\Util\ViewRenderer->getContents() #3 /...path-to-my-wordpress.../wp-content/plugins/wp-opening-hours/classes/OpeningHours/Module/Shortcode/IsOpen.php(86): OpeningHours\Module\Shortcode\AbstractShortcode->renderShortcodeTemplate(Array, '/...path-to-my-wordpress...') #4 /...path-to-my-wordpress.../wp-content/plugins/wp-opening-hours/classes/OpeningHours/Module/Shortcode/AbstractShortcode.php(97): OpeningHours\Module\Shortcode\Is in /...path-to-my-wordpress.../wp-content/themes/my-child-theme/wp-opening-hours/orari.php on line 29

    (Line 29 is in the original overview template and reads: $description = $set->getDescription();. But I’m pretty sure it shouldn’t be picking up my template anyway.)

    What do I need to specify in my functions.php to tell the plugin to override the overview template, but not the others?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author janizde

    (@janizde)

    Hi @electricfeet ,

    nice that you have managed to get it working with the filter ??
    Referring to the example usage of the filter ( https://github.com/janizde/WP-Opening-Hours/blob/master/doc/filters.md#op_shortcode_template ) you can see that you can check the kind of shortcode with if ($shortcode instanceof ShortcodeModule). In your case it should be the OpeningHours\Module\Shortcode\Overview then.

    Cheers
    Jannik

    If you have further questions you can reply in this thread, I’ve enabled email notifications for this.

    Thread Starter ElectricFeet

    (@electricfeet)

    @janizde Thanks Jannik!

    That worked a treat.

    Unfortunately, the documentation is a little beyond my competence level so I had previously seen the link you gave above and stripped out all the stuff I didn’t understand, with inevitable results :-)))

    (I still don’t understand classes and the use statement, but as an incantation to the php gods, it works, so I won’t omit it again.)

    I can now combine the is-open shorcode with the overview shortcode on the same page with no problems.

    Thanks again for all your patient help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error using template file’ is closed to new replies.