问题
How do I remove the title on WooCommerce products when they are posted as short codes?
[product_page id="99"]
I am getting a double title:
- on the shortcode product embed
- on the actual blog post
I would like to disable to title on the shortcode only and keep the title on the blog post, but keeping the title on the shop page.
回答1:
Those titles are hooked in content_single-product.php
WooCommerce template file as you can see below:
/**
* woocommerce_single_product_summary hook.
*
* @hooked woocommerce_template_single_title - 5 // <=== HERE
* @hooked woocommerce_template_single_rating - 10
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
*/
To remove the product page titles only from your blog posts and pages, when outputted from a shortcode, you will need to add a condition when removing the title in the woocommerce_single_product_summary
hook.
Here is that functional and tested code:
function remove_some_product_titles(){
if( !is_product() ){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5);
}
}
add_action( 'woocommerce_single_product_summary', 'remove_some_product_titles', 4);
Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
回答2:
You can remove the title action using this:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
Let me know if it worked.
来源:https://stackoverflow.com/questions/40955866/product-shortcode-removing-product-title-on-blog-posts-and-pages