Woocommerce Simple Product to Group product

#140739
  • Resolved Adam
    Rank Math free

    Hi Guys,

    We were using the folloowing code for a site of which we noindex/nofollowed all Simple products, allowing the grouped products to be indexed ( using ALL IN ONE SEO )

    Unfortunately, we’ve found that this code stopped working, most likely a result of ALL IN ONE SEO big update.

    So after switching to RANK MATH on a few other sites, I’d like to do the same for this site, but does anyone have any code which can do what we need with rank math.

    add_filter('wp', 'wp_dev');
    function wp_dev(){
         $post_id = get_the_ID();
    
         if ('product' == get_post_type($post_id)) {
            $_product = wc_get_product( $post_id );
            if( $_product->is_type( 'simple' ) ) {
                update_post_meta( $post_id, '_aioseop_noindex', 'on' );
                update_post_meta( $post_id, '_aioseop_nofollow', 'off' );
    	    update_post_meta( $post_id, '_aioseop_custom_link', 'GROUPED PRODUCT PERMALINK ?????' );
             }
        }
    }
    
    

    So essentially, because alot of the pages are now indexed as a result of this mistake. Id like to do the following

    1. Noindex all Single products
    2. follow all single products
    3. Set custom canonical to grouped product parent.

    Any help in achiving this would be much appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Roel John
    Rank Math business

    Hello,

    Thank you for contacting Rank Math.

    Please use the code below. The code will set all the robots meta tags into noindex and follow in all single product page.

    
    /**
     * Rank Math: filter the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
        if ( is_product() ){
    		$robots['follow'] = 'follow';
    		$robots['index'] = 'noindex';
        }
    return $robots;
    }); 
    

    About the canonical tag. Since we set your single product into noindex. Rank Math will automatically remove the canonical meta tags on all single product page.

    Please let us know if this helps.

    Thank you, and looking forward to your update.

    Adam
    Rank Math free

    Thanks for that,

    Is there a way we could possibly use another function to add a canonical manually ?

    Obviously with the page still being followed, we’d like to ensure the correct canonicals can be set to bring focus back to the grouped product pages.

    ALSO I see your code specifies “PRODUCT” which i assume means your code would apply to ALL products, including grouped products. Where as our code specified it only applied to simple products

    Roel John
    Rank Math business

    Hello,

    Please check the code below. The code below will change your robots into follow and noindex to all simple products.

    
    /**
     * Rank Math: filter the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	$post_id = get_the_ID();
    	if ('product' == get_post_type($post_id)) {
    		$_product = wc_get_product( $post_id );
    		if( $_product->is_type( 'simple' ) ) {
    		 $robots['follow'] = 'follow';
    		 $robots['index'] = 'noindex';
    		 }
    	}
    	return $robots;
    }); 
    

    It’s not possible and that’s how Rank Math canonical works. As long you set your post type to noindex you can’t put a canonical tag on that post type.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Woocommerce Simple Product to Group product’ is closed to new replies.