The following snippet will add a second custom button called “Learn More” on the product category pages of WooCommerce. This works great when utilizing external/affiliate products with WooCommerce. This function has been tested with the latest version of WooCommerce and the Divi Builder.
Use this custom function hooked in woocommerce_after_shop_loop_item action hook, to add your custom button linked to the product, except variable and grouped product types. Add the following code to your themes functions.php file.
add_action('woocommerce_after_shop_loop_item', 'add_a_custom_button', 5 ); function add_a_custom_button() { global $product; // Not for variable and grouped products that doesn't have an "add to cart" button if( $product->is_type('variable') || $product->is_type('grouped') ) return; // Output the custom button linked to the product echo '<div style="margin-bottom:0px; text-align:center;"> <a class="button custom-button" href="' . esc_attr( $product->get_permalink() ) . '">' . __('Learn More') . '</a> </div>'; }
This code will add a second custom button on the WooCommerce category pages called “Learn More”. This button will link to the individual product page. In the case of my website, I am using external/affiliate products and the default “Shop Now” button links to the affiliate website.
Leave a Reply