• Resolved DivaVocals

    (@divavocals)


    Before anyone suggests going to WooCommerce for assistance with their plugin (https://woocommerce.com/products/brands/?aff=10486&cid=1131038), I already have and they are not willing to provide help with what REALLY IS a minor modification.

    I don’t see anyway to hide the display of the brands on the single product page. We want to tie our products to brands and manage the brands in the admin ONLY for reporting purposes, but we do not want to display brand info on the single product or product archive pages. There is no way to hide this using CSS as it shares the same CSS class as the products categories.

    I found the code that contains the target HTML I am after:
    class-wc-brands.php

    In this file on lines 336-354 (see code below) I want to make the following change:
    Replace: <span class=”posted_in”>
    With: <span class=”brands_wrapper”>

    This minor change will allow me to very simply hide the brands from displaying on the product pages using CSS. I know I can edit this file directly, but I also know it’s a bad practice to modify plugin files like this. Hoping I can get help creating a code snippet to override this part of the plugin so that I do not have to make this change again at every update.

    	/**
    	 * show_brand function.
    	 *
    	 * @access public
    	 * @return void
    	 */
    	public function show_brand() {
    		global $post;
    
    		if ( is_singular( 'product' ) ) {
    			$terms       = get_the_terms( $post->ID, 'product_brand' );
    			$brand_count = is_array( $terms ) ? sizeof( $terms ) : 0;
    
    			$taxonomy = get_taxonomy( 'product_brand' );
    			$labels   = $taxonomy->labels;
    
    			echo get_brands( $post->ID, ', ', ' <span class="posted_in">' . sprintf( _n( '%1$s: ', '%2$s: ', $brand_count ), $labels->singular_name, $labels->name ), '</span>' );
    		}
    	}

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • It looks like you have managed to do this.

    Thread Starter DivaVocals

    (@divavocals)

    @lorro I actually have not managed to do this (override the plugin with a code snippet). ??

    What I did manage to do is to directly edit the plugin files to modify the target CSS class so I could hide the CSS and give my client what he wanted immediately. However, this is exactly what I do not want as a long term solution. I still need to know how to override this plugin’s function using a code snippet.

    As I stated WooCommerce refuses to offer any assistance with modifying their plugin (https://woocommerce.com/products/brands/?aff=10486&cid=1131038) with what REALLY IS a minor modification.

    I hope you have a potential solution to share. ??

    Unfortunately I don’t have that plugin so I don’t have its code to look at and as its premium I can’t download it. I expect that will apply to other potential helpers on here.

    My best guess is that they have used the ‘woocommerce_product_meta_end’ action to insert the Brands markup. Copy the plugin to your hard drive and text-search for the above string. It’ll be in a line something like this:

    add_action( 'woocommerce_product_meta_end', 'name_of_woocommerce_add_brands_markup_function', 40 ):

    In this example, your remove code in functions.php would look like this:

    remove_action( 'woocommerce_product_meta_end', 'name_of_woocommerce_add_brands_markup_function', 40 ):

    Note that the hook name, the woocommerce-brands function name and the priority (if present) must be the same in the remove() as it is in the add().

    If your theme has overridden meta.php, look for the theme version at:
    wp-content/themes/your-theme-name/woocommerce/single-product/meta.php
    and find the hook name from there.

    Alternatively, when you tried css did you try the nth-child selector. It would go like this:

    body.woocommerce-page .summary .product_meta span:nth-child(3) {
      display: none !important;
    }

    If you add or delete other meta entries, then the “3” would change accordingly.

    madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    @lorro this is super impressive! The Brands section of the product page is hooked into woocommerce_product_meta_end indeed ??

    @divavocals this should do the trick:

    
     remove_action( 'woocommerce_product_meta_end', array( $GLOBALS['WC_Brands'], 'show_brand' ) );
    

    Cheers!

    • This reply was modified 5 years, 1 month ago by madeincosmos.
    Thread Starter DivaVocals

    (@divavocals)

    @madeincosmos THANK YOU THANK YOU THANK YOU!! That did the trick!!!!!! I would hope that WooCommerce would AT LEAST add an admin option to allow shop owners to decide if they want to display the brands info on the front-end.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Help Modifying WooCommerce Brands Plugin to Hide Brands on Product Pages’ is closed to new replies.