Okay
  Public Ticket #3045968
Show Related Products Regardless of Category
Closed

Comments

  •  10
    Ellison started the conversation

    Hi - this site currently only has 4 products, but this number will grow. There are only 2 categories - Doors and Hardware. I would like for the products categorized as Hardware to display on the single product page for doors (because this is the other thing they need to buy to go with the door). Is there any way to adjust what category displays in the Related Products section?

  •  1,877
    Judith replied

    Hello Ellison,

    Thanks for keeping in touch.

    Please check out this article https://stackoverflow.com/questions/70884650/display-woocommerce-related-products-by-current-category-and-tags.

    Hope this helps.

    Thanks.

  •  10
    Ellison replied

    OK - I'm not very good at filters/php stuff. Can you tell me how I would adjust this to work in my situation? Do I add this line and change 'product_cat' to be the category I want to display? Is everything else in this line of code relevant?

    apply_filters( 'woocommerce_get_related_product_cat_terms', wc_get_product_term_ids( $product_id, 'product_cat' ), $product_id );
    

  •  1,877
    Judith replied

    Hi Ellison,

    Please allow me to escalate this to the developer to respond further.

    Thanks.

  •  1,070
    ThemeNectar replied

    Hey Ellison,

    The following snippet can be added to your child functions.php file to allow any product to be shown in the related category section:

    add_filter('woocommerce_product_related_posts_relate_by_category', 'salient_child_mod_woo_related');
    function salient_child_mod_woo_related() {
      return false;
    }
    add_filter('woocommerce_product_related_posts_force_display', 'salient_child_mod_woo_related_forced');
    function salient_child_mod_woo_related_forced() {
      return true;
    }
    
    Kind regards,