Using different themes on different products

By default, the configurator theme is set for the whole website. It is however possible to programatically override the selected theme by using the mkl/pc/theme_id filter.

Example:

add_filter( 'mkl/pc/theme_id', function( $default ) {
    // Maybe override the theme ID
    if ( $something_is_true ) {
        return 'other_theme_id';
    }

    // Return the default one otherwise
    return $default;
} );

You can for example set this to use the current post’s custom fields in order to override the theme:

add_filter( 'mkl/pc/theme_id', function( $default ) {
	global $post;
	// Check if there is a global post
	if ( ! is_a( $post, 'WP_Post' ) ) return $default;
	// Get the theme ID stored in the 'mkl_custom_page_theme' post meta
	if ( get_post_meta( $post->ID, 'mkl_custom_page_theme', true ) ) return get_post_meta( $post->ID, 'mkl_custom_page_theme', true );
	// Fallback to the main theme
	return $default;
} );

You can then use this custom field in the product:

Was this page helpful?
Leave a Reply

Your email address will not be published.