0

I'm developing a child-theme off of the Twenty Twelve (1.1), using Wordpress (3.5.1) and the Woocommerce plugin (1.6.6).

I've noticed that the problem with creating the online shop, single product page and the taxonomy pages (categories and tags), is that it uses it's own templates to display these pages (which can be customized), but making changes to the other pages such as the checkout, cart, my account etc. won't be affected because they are referenced from the theme’s page.php template.

Because of this, I would like to display additional template pages to choose from when the Woocommerce plugin is activated in the Page Attributes list and hidden/not displayed otherwise.

For example, by default:

  • Full-Width
  • Full-Width, Sidebar Right
  • One-Third, Two-Thirds Columns
  • Three Columns, Sidebar Right

And when the Woocommerce is activated:

  • Full-Width
  • Full-Width, Sidebar Right
  • One-Third, Two-Thirds Columns
  • Shop, Sidebar Left <-------
  • Shop, Sidebar Right <-------
  • Three Columns, Sidebar Right

Is this possible and can an additional sidebar in the widgets menu (Shop Sidebar) also be created on the plugin activation?

Thank you.

3 Answers 3

1

Instead of using page templates to define layouts, define layouts using custom post meta. The custom post meta can then be shown or not shown using is_plugin_active().

If you're going to define the page template itself in the Theme, then you're pretty much stuck with doing something like determining if the Plugin is active (which, on the front end, should be done using a function_exists() conditional or something similar), and including the default template if not. For example:

/**
 * Template Name: Shop
 */

if ( ! function_exists( 'some-woocommerce-function' ) ) {
    get_template_part( 'page' );
} else {

// Shop template markup goes here

}

That way, even if the template is selected, it will gracefully degrade.

0

You could add a sidebar area after checking is_plugin_active().

See this question regarding page templates and the page attributes meta box. I think your only options are to copy the files in, or create your own page attributes meta box while hiding the original.

0

I scoured pretty long and far hoping that a filter or action would be somewhere but I couldn't seem to find anything.

You could hack it up with JS like so..

// Change woocommerce to whatever the plugin's folder path is
if(!is_plugin_active('woocommerce')) {
    // Create a quick array incase you want to quickly add or change the templates you are removing
    $remove_templates = array('template-number-1.php','template-number-2.php','...');
    ?><script type="text/javascript">
        // jQuery because I don't know anything else
        jQuery(document).ready( function($) {
            <?php foreach($remove_templates as $template) : ?>
                $('#page_template').find('option[value="<?php echo $template ?>"]').remove();
            <?php endforeach; ?>
        }
    </script><?php 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.