Code Snippets is a free plugin that allows you add code snippets to your site without the need to edit theme. This is the recommended way of adding custom code snippets since updating the newer version of themes may overwrite custom added code.
Install Code Snippets plugin
- From Wordpress admin, go to Plugins > Add New.
- Search for Code Snippets plugin and install it.
Adding Snippets
- Go to Snippets > Add New to add a new snippet.
- Select Only run on site front-end so that snippet is only run on user-facing store.
In this example, we are adding a snippet to render reviews widget for visual hook "woocommerce_after_single_product".
add_action('woocommerce_after_single_product', 'render_onvoard_reviews_widget'); function render_onvoard_reviews_widget() { if (class_exists('OnVoardRender')) { OnVoardRender::onvoard_reviews_widget(array( "id" => "rwget_8hed8ooew28t59a" )); } }
You can add any code snippet you want, as long as it is valid php script.