Envira Gallery Documentation

Documentation, Reference Materials and Tutorials for Envira Gallery

How to use override your Woocommerce Redirect for Envira Galleries

Would you like to override your Woocommerce redirect settings when viewing an Envira gallery? We can easily help you with that! If you’d like to have the user remain on the Envira Gallery page after using the Add to Cart button then this tutorial is exactly what you need! We’ll walk you through all the steps on how to override these settings.

This tutorial is a bit more technical than our other docs, but we’ll walk you through the process step by step. In order to override the Woocommerce redirect settings, we’ll need to create and upload a basic WordPress plugin.

Creating the Plugin

To override the Woocommerce redirect settings, just add the following code to a new file at wp-content/plugins/envira-gallery-stay-on-woo-gallery-page.php.

<?php
/**
* Plugin Name: Envira - Stay on gallery page
* Plugin URI: https://enviragallery.com
* Version: 1.0
* Author: Envira Gallery Team
* Author URI: https://enviragallery.com
* Description: Overrides the setting to direct to cart and stay on gallery page
*/

add_filter( 'envira_gallery_pre_data', 'woocommerce_example_envira_gallery_pre_data', 10, 2 );
function woocommerce_example_envira_gallery_pre_data( $data, $gallery_id ) {
	$data['config']['woocommerce_add_to_cart_redirect'] = 'self';
	return $data;
}

If you’re unsure how to create a plugin file, follow these steps below:

  1. Open a text file and make sure that it is a plain text document. You can use a plain text editor like Notepad or a code editor of your choice.
  2. Next, copy and paste the code shown above into the file and save the file as envira-gallery-stay-on-woo-gallery-page.php.
  3. Once you’ve saved the file you can easily upload this directly to your /plugins directory on your server using FTP or you can right-click on the text document and zip (or compress).
  4. Finally, log in to your WordPress dashboard and go to Plugins » Add New » Upload Plugin and upload the .zip file you just created in the previous step.

Activate the Plugin

Your next step is to activate the plugin you just uploaded. Simply navigate to the Plugins from within your WordPress dashboard and activate the Envira – Stay on gallery page plugin.

Activate the Envira - Stay on gallery page plugin

That’s it! Check out our full documentation on How to use the Woocommerce Addon.


FAQs

Q: Is this the only way?

A: Not at all! If you’d like to disable the automatic redirect to the check out page, just go to your Woocommerce » Settings »Products tab, uncheck the Add to cart behaviour that is set to Redirect to the cart page after successful addition and then click Save to save the changes.

Disable the redirect to the cart page in the Woocommerce settings