• Resolved Tuba Saif

    (@tuba121)


    Hello , I wanna remove product meta(sku, category) from single product page. I tried different codes but nothing work. I am providing a code

    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_title’, 5 );

    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_rating’, 10 );

    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’, 10 );

    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_excerpt’, 20 );

    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_meta’, 40 );

    remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_sharing’, 50 );

    This code just working for NEVE theme but not for other theme , can you help me to find a way for removing product categories using PHP(not css).

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    Hi there,

    To remove the product meta (SKU, categories, tags) from the single product page in WooCommerce, you need to unhook the woocommerce_template_single_meta action from the woocommerce_single_product_summary hook. The code you provided seems correct for this purpose, but it’s important to note that the quotes used in your code are not standard single quotes—they are typographic quotes, which can cause issues in PHP. Make sure to use standard single quotes or double quotes in your PHP code.

    Here’s the corrected code:

    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

    To ensure that this code works regardless of the theme, you should place it in your child theme’s functions.php file, or in a custom plugin. Additionally, it’s possible that some themes or plugins might alter the default WooCommerce hooks or priorities. In such cases, you may need to adjust the priority of your remove_action calls to ensure they execute after the theme or plugin has added its actions.

    If the code still doesn’t work, you may need to increase the priority of the remove_action call to ensure it runs after the actions have been added by the theme or plugin. For example:

    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 100 );

    If you’re unsure about the correct priority to use, you can try using a very high number to ensure your remove_action is called last.

    Finally, if your theme or a plugin is using a different hook or function to display the product meta, you will need to investigate the theme or plugin files to find the correct hook and callback function name to remove.

    As a last resort, if you’re unable to find the correct hook or if the theme is hardcoding the meta without using actions, you can override the woocommerce_template_single_meta function in your child theme. You would copy the original function from woocommerce/templates/single-product/meta.php to your child theme’s WooCommerce folder (typically your-child-theme/woocommerce/single-product/meta.php) and then make your changes there. However, this should be a last resort as it can make future updates more difficult.

    Thread Starter Tuba Saif

    (@tuba121)

    @riaanknoetze Thanks for covering all aspects. I tried with changing priorties. Now finding the theme specific hooks and functions but i provide a code for price please look into it ,It is modifying the HTML code.

    add_filter(‘woocommerce_get_price_html’, ‘disable_product_prices’, 10, 2);

    function disable_product_prices($price_html, $product) {

        // Return empty string to disable price display

        return ”;

    } Is their any way for categories like price.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @tuba121,

    Is their any way for categories like price

    Are you looking to hide the product category? If so, you can use the code snippet shared here to hide or remove the product category name from the single product page.

    I hope this helps! Please let us know how it goes or if you need further assistance.

    Thread Starter Tuba Saif

    (@tuba121)

    Not working , just working for neve theme.Is their any way to remove category using filter and action hooks?that works for all themes

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @tuba121,

    The code snippet shared on the Business Bloomer site used action hooks and worked fine on my testing site, where I use the Storefront theme.

    Are you using the Neve theme by any chance? If that’s the case, I can assure you that it works perfectly on the Neve theme too. I’ve tested it with the Neve theme, which worked like a charm.

    However, if you’re using a Block-based theme, you might not get the expected results. You might have to use CSS to hide it in such a scenario. For better assistance, could you please share your site URL?

    Looking forward to hearing from you soon.

    Thread Starter Tuba Saif

    (@tuba121)

    Thanks shameem Reza , I am not using Neve theme , I am learning that’s why I checked on 15 themes , it’s working in Neve , I want consistent code( if any ) that work for all theme.

    Now I found this code.

    // Disable category on product page function custom_product_meta_end() { $buffered_content = ob_get_clean(); $modified_content = preg_replace(‘/<span class=”posted_in”>(.*?)<\/span>/’, ”, $buffered_content); echo $modified_content; } add_action(‘woocommerce_product_meta_end’, ‘custom_product_meta_end’);

    • This reply was modified 12 months ago by Tuba Saif.
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @tuba121,

    Does that code work with every theme you’ve tested? Most of the WooCommerce code snippets found on various sites use WooCommerce action hooks to hide different elements. However, they’ll only work with the classic theme. They might not work as expected with block-based themes because they work differently.

    Additionally, It’s fantastic that you’re taking the time to learn WooCommerce! If you need additional assistance, don’t hesitate to reach out to our vibrant WooCommerce community. Our WooCommerce community is brimming with skilled open-source developers who are always active and ready to help on the following channels:

    I hope this clarifies your concern. If you have any other questions, feel free to ask.

    Thread Starter Tuba Saif

    (@tuba121)

    Means action/filter hooks may not work on block theme because it uses different structure.right? but they work in classic theme?-I found different ways for removing elements. using init, wp, wphead, template redirect. and one more question- I think blocksy theme using block theme structure because i tried hard to find hooks in its template files but not being found.

    Thread Starter Tuba Saif

    (@tuba121)

    I found many themes remove woocommerce default hooks and make their own .I think that’s why woocommerce general hooks not works for them. Now i found a solution for removing meta and base category from woocommerce single product but struggling with removing breadcrumb from woocommerce single product page. Following is the code for category.

    function remove_category($terms, $post_id, $taxonomy) {
    if (is_product() && ‘product_cat’ === $taxonomy) {
    $default_categories = get_terms(array(
    ‘taxonomy’ => ‘product_cat’,
    ‘hide_empty’ => false,
    ));
    $default_category_slugs = array();
    foreach ($default_categories as $default_category) {
    $default_category_slugs[] = $default_category->slug;
    }
    foreach ($terms as $key => $term) {
    if (in_array($term->slug, $default_category_slugs)) {
    unset($terms[$key]);
    }
    }
    }
    return $terms;
    }
    add_filter(‘get_the_terms’, ‘remove_category’, 10, 3);

    Hi @tuba121,

    Thanks again for reaching out.

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    In the meantime, I found an interesting external thread here that seems to describe what you are trying to achieve.

    I hope that points you in the right direction.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘remove product meta from single product page.’ is closed to new replies.