Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

WooCommerce actions not working, maybe theme issue?

$
0
0

Hi,

In my WooCommerce Views setting I use "Use WooCommerce default templates".

So I edited my single-product.php and placed it in the WooCOmmerce folder of my Toolset bootstrap child theme.

It looks like this:

<?php
/**
 * The Template for displaying all single products.
 *
 * Override this template by copying it to yourtheme/woocommerce/single-product.php
 *
 * @author 		WooThemes
 * @package 	WooCommerce/Templates
 * @version     1.6.4
 */

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

get_header(); ?>

	<?php
		/**
		 * woocommerce_before_main_content hook
		 *
		 * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
		 * @hooked woocommerce_breadcrumb - 20
		 */
		do_action('woocommerce_before_main_content');
	?>

		<?php while ( have_posts() ) : the_post(); ?>

			<?php woocommerce_get_template_part( 'content', 'single-product' ); ?>

		<?php endwhile; // end of the loop. ?>

	<?php
		/**
		 * woocommerce_after_main_content hook
		 *
		 * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
		 */
		do_action('woocommerce_after_main_content');
	?>

<?php get_footer(); ?>

You can see two do_actions there:

woocommerce_before_main_content
woocommerce_after_main_content

In woocommerce-hooks.php you can find:

	/**
	 * Content Wrappers
	 *
	 * @see woocommerce_output_content_wrapper()
	 * @see woocommerce_output_content_wrapper_end()
	 */
	add_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
	add_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );

In woocommerce-template.php you can see this should load two woocommerce template files:

/** Global ****************************************************************/

if ( ! function_exists( 'woocommerce_output_content_wrapper' ) ) {

	/**
	 * Output the start of the page wrapper.
	 *
	 * @access public
	 * @return void
	 */
	function woocommerce_output_content_wrapper() {
		woocommerce_get_template( 'shop/wrapper-start.php' );
	}
}
if ( ! function_exists( 'woocommerce_output_content_wrapper_end' ) ) {

	/**
	 * Output the end of the page wrapper.
	 *
	 * @access public
	 * @return void
	 */
	function woocommerce_output_content_wrapper_end() {
		woocommerce_get_template( 'shop/wrapper-end.php' );
	}
}

And that is where the problem is > that is not happening.

I only solved the problem by adding this to my child theme functions.php, but that should not be necesarry, because on the Github from woocommerce nobody else was experiencing the problem I have.

This is the temporary solution:

// Note:
// 1) Overwriting shop/wrapper-end.php and shop/wrapper-start.php was not enough, because those actions calling these templates are not working for some reason
// 2) See https://github.com/woothemes/woocommerce/issues/4376
// 3) See 
add_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 20 );
add_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 20 );

Kind regards,

Willem


Viewing all articles
Browse latest Browse all 20145

Trending Articles