How to Add WooCommerce Shop as a Breadcrumb Archive item on Launchpad Platform

This guide will help you customize the breadcrumb item link for the archive page on your Launchpad Platform WordPress site. In this post, you learn how to enable and modify the breadcrumb item for the shop archive page to direct users to the shop page of your site. Please note that the Launchpad Products Add-on plugin already supports this and there is no need to customize unless the link and text are customized to what it supposed to be originally.

1. Includes Archive on Breadcrumbs

  • To begin, log in to your WordPress admin dashboard.
  • Next, navigate to Launchpad menu, select Site Settings, and then go to Pages tab
  • In the Sub-pages / Internal Page group options make sure Breadcrumb is enabled then tick on Archive on the Links Included on Breadcrumb.

2. Access Your Theme’s Functions File

  • Navigate to the “Appearance” menu and select “Theme Editor.”
  • In the right-hand panel, you’ll see a list of theme files. Find and click on the “functions.php” file associated with your currently active theme which are usually a child theme.

3. Insert the Provided Code

  • Once you’ve opened the “functions.php” file, scroll to the bottom or a convenient location for adding custom code.
  • This can also be done if you have installed code snippets plugin in your WordPress site like WPCode and Code Snippets to insert the code.
  • Copy and paste the following code snippet into the “functions.php” file:
add_filter( 'hi_breadcrumbs_archive_page', function( $archive_page ){
    $post_type = ''; 
	if( is_singular('product') ){
		global $post;

		$post_object = sanitize_post( $post );
		$post_type   = $post_object->post_type;
	} elseif(is_product_category()) {
		$term_object        = get_queried_object();
		$term_parent        = $term_object->parent;
		$taxonomy           = $term_object->taxonomy;

		$taxonomy_object    = get_taxonomy($taxonomy); 
		if (isset($taxonomy_object->object_type) && !empty($taxonomy_object->object_type)) {
			$post_types = $taxonomy_object->object_type;

			if( ! empty( $post_types ) && count( $post_types ) == 1 ){
				$post_type = $post_types[0] ;
			}
		}
	} 

	if( $post_type  == 'product' ){
		if( class_exists('Woocommerce') ){
			$shop_page = wc_get_page_id( 'shop' );
  
          if( $shop_page ){
				$archive_page = array(
					'label' => get_the_title( $shop_page ),
					'url' => get_permalink( $shop_page )
				);
		} 
		}
	} 

	return $archive_page;
} );

This documentation provides a comprehensive guide for implementing and comprehending the provided code. You can further customize this code to adapt to your specific requirements.
By following these steps and considering the customization options, you can effectively control the archive link on the breadcrumb to go to your Shop page. Feel free to adjust and format it according to your website’s documentation style.

3. Understanding the Code

  • This code uses the add_filter function to dynamically customize the link of the archive page link displayed in your Launchpad Platform WooCommerce WordPress site’s breadcrumbs by hooking the function to hi_breadcrumbs_archive_page.
  • The function is_singular('product') and the WooCommerce function is_product_category() checks if the current page is a product single or category page making sure the Shop archive page only affects product pages breadcrumb item for the archive page.
  • Once the code determines that the page is for the product post type, it will get the shop page depending on your website. WooCommerce has its settings to define the shop page and we can get this using wc_get_page_id( 'shop' ) which returns the shop page id. If your theme or plugin has another setting that overrides the WooCommerce shop page, you can change the logic based on your requirements.

4. Save Changes

After adding the code, click the “Update File” button (for themes) or save your plugin file to apply the changes.

5. Testing

To test the code, visit product pages including single and category pages on your WordPress site. You should now see the custom archive page link on the breadcrumb that displays and directs users to shop.