Add WooCommerce Support

To make WooCommerce fully compatible with Marketers Delight, you can add the following functions and meta box filters to your MD child theme.

WooCommerce recommends wrapping their content in your theme’s wrapper classes so everything from the Checkout page to shop pages align properly and inherit some of your theme’s styling.

Paste these functions into your child theme (or create a new file) to add WooCommerce support and wrap Woo content with MD’s wrapper classes:

/**
 * Setup child theme elements.
 *
 * @since 1.0
 */

function md_after_setup_theme() {
    add_theme_support( 'woocommerce' );
}

add_action( 'after_setup_theme', 'md_after_setup_theme' );


/**
 * Unhook WooCommerce wrappers and implement MD content wrappers.
 *
 * @since 1.0
 */

function md_woo_wrapper_start() { ?>

	<div id="content-box" class="content-box inner block-double-tb<?php md_content_box_classes(); ?>">

		<main class="content format-text-main content-item <?php echo md_content_block(); ?>" role="main" itemprop="mainContentOfPage">

<?php }


function md_woo_wrapper_end() { ?>

		</main>

		<?php get_sidebar(); ?>

	</div>

<?php }

remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );

add_action( 'woocommerce_before_main_content', 'md_woo_wrapper_start', 10 );
add_action( 'woocommerce_after_main_content', 'md_woo_wrapper_end', 10 );

Next, if you want to enable MD’s meta box controls (Layout options, Page Leads, Featured Image position, etc.) to WooCommerce single product pages and categories, you can use these filters (added in MD4.5) to do so:

/**
 * Add MD metaboxes to other CPTs.
 *
 * @since 1.0
 *
 */

function md_meta_post_types( $post_type ) {
	$post_type[] = 'product';
	return $post_type;
}

add_filter( 'md_post_types_meta', 'md_meta_post_types' );


/**
 * Add MD metaboxes to taxonomies.
 *
 * @since 1.0
 * @requires MD4.3.5
 */

function md_meta_taxonomies( $taxonomy ) {
	$taxonomy[] = 'product_cat';
	return $taxonomy;
}

add_filter( 'md_taxonomy_meta', 'md_meta_taxonomies' );

Leave a Comment