Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #2950651
An option to disable on specific products
Closed

Comments

  •  7
    Alvaro started the conversation

    I have some products on my site, which are bundles or wholesale, so i would like to disable bought together on those. 

  •  767
    Janilyn replied

    Hi Alvaro,

    Thank you for contacting WPClever Support Forum. 

    We’ve received your ticket and assigned one of our developers to help you with that. 

    He’ll be looking into your question and responding with specific instructions as soon as possible. 

    Please stay patient as we're having very heavy workloads, it might take some time for our developers to reach back.

    Best regards.

    Janilyn T. - WPClever Support Agent

  •  1,226
    Dustin replied

    Hi Alvaro,

    Please follow these steps:

    1. Update our plugin to the latest version 4.1.2

    2. Add the below custom code (How to add custom code?)

    add_filter( 'woobt_show_items', 'woobt_hide_for_some_products', 99, 2 );
    function woobt_hide_for_some_products( $items, $product_id ) {
        // product IDs that you want to hide frequetly bought together
        $ids = array( 1906, 1992, 2000, 2022 );
        if ( in_array( $product_id, $ids, true ) ) {
            return false;
        }
        return $items;
    }

    You can change the product IDs (1906, 1992, 2000, 2022) in this snippet as you want.

    Best regards,
    Dustin

  •  7
    Alvaro replied

    Thanks Dustin!


    I used to make a better usable solution:


    // Hide related products from the single product edit page
    // 1. Add new checkbox product edit page
    add_action( 'woocommerce_product_options_related', 'checkbox_sacar_relacionado' );        
    function checkbox_sacar_relacionado() {           
    woocommerce_wp_checkbox( array( 
       'id' => 'hide_related', 
       'class' => '', 
       'label' => 'Esconde los productos relacionados'
       ) 
    );      
    }
      
    // 2. Save checkbox into custom field
      
    add_action( 'save_post_product', 'guardar_opcion_esconder' );
    function guardar_opcion_esconder( $product_id ) {
       global $pagenow, $typenow;
       if ( 'post.php' !== $pagenow || 'product' !== $typenow ) return;
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
        if ( isset( $_POST['hide_related'] ) ) {
          update_post_meta( $product_id, 'hide_related', $_POST['hide_related'] );
        } else delete_post_meta( $product_id, 'hide_related' );
    }
      
    // 3. Hide related products @ single product page
    add_filter( 'woobt_show_items', 'woobt_hide_for_some_products', 99, 2 );
    function woobt_hide_for_some_products( $items, $product_id ) {
        if ( ! empty( get_post_meta($product_id, 'hide_related', true ) ) ) {
            return false;
        }
        return $items;
    }


  •  7
    Alvaro replied

    and this for categories:

    add_filter( 'woobt_show_items', 'woobt_hide_for_some_products', 99, 2 );
    function woobt_hide_for_some_products( $items, $product_id ) {
    if( has_term( array( 'six-pack', 'backpacks' ), 'product_cat', $product_id)) {
    return false;
    }
    return $items;
    }