Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created March 24, 2025 11:44
Show Gist options
  • Save webtoffee-git/963bfa1fa4da6c5c18b006c865c4665b to your computer and use it in GitHub Desktop.
Save webtoffee-git/963bfa1fa4da6c5c18b006c865c4665b to your computer and use it in GitHub Desktop.
To hide default related products when using related products shortcode – By WebToffee(Related Products - Create Upsells, Cross-sells, and Product Recommendations for WooCommerce)
<?php //Do not copy this line of code
/**
* Hide default related products when [wt-related-products] shortcode is used
*/
function wt_custom_hide_default_related_products() {
if (is_product()) {
global $post;
if ($post && has_shortcode($post->post_content, 'wt-related-products')) {
// Remove WooCommerce's default related products
remove_action('woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
}
if (is_cart()) {
$cart_page_id = get_option('woocommerce_cart_page_id');
if ($cart_page_id) {
$cart_page = get_post($cart_page_id);
if ($cart_page && has_shortcode($cart_page->post_content, 'wt-related-products')) {
// Remove the plugin's automatic rendering for cart
remove_action('woocommerce_after_cart', array('Custom_Related_Products', 'render_related_products_in_cart'));
remove_filter('render_block', array('Custom_Related_Products', 'render_related_products_in_block_cart'), 10);
}
}
}
}
add_action('wp', 'wt_custom_hide_default_related_products');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment