Add ability to suppress titles to product_page shortcode

This commit is contained in:
claudiulodro 2017-11-13 10:36:58 -08:00
parent f58e4d4b85
commit 9cc69ea021
2 changed files with 11 additions and 1 deletions

View File

@ -498,6 +498,11 @@ class WC_Shortcodes {
$args['p'] = absint( $atts['id'] );
}
// Don't render titles if desired.
if ( isset( $atts['show_title'] ) && ! $atts['show_title'] ) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
}
$single_product = new WP_Query( $args );
$preselected_id = '0';
@ -565,6 +570,11 @@ class WC_Shortcodes {
// @codingStandardsIgnoreEnd
wp_reset_postdata();
// Re-enable titles if they were removed.
if ( isset( $atts['show_title'] ) && ! $atts['show_title'] ) {
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
}
return '<div class="woocommerce">' . ob_get_clean() . '</div>';
}

View File

@ -290,7 +290,7 @@ class WC_Template_Loader {
// Unsupported theme product page.
} elseif ( is_product() ) {
$content = do_shortcode( '[product_page id="' . get_the_ID() . '"]' );
$content = do_shortcode( '[product_page id="' . get_the_ID() . '" show_title=0]' );
}
self::$in_content_filter = false;