• Home
  • About Us
  • Digital Marketing Terms
  • Free Tech Support
  • Contact Us
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Code Snippets

Real Answers From Real Developers

  • WordPress General
  • Divi Builder Tutorials
  • WordPress Plugins
  • Local SEO
  • Show Search
Hide Search

Add Custom Button On Product Category Pages WooCommerce

code-admin · July 20, 2020 · Leave a Comment


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.

Filed Under: WooCommerce Snippets

You May Also Like

Change Title Position To Above Product Image WooCommerce

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • The Site is Experiencing Technical Difficulties WordPress
  • Using Flexbox CSS To Center Elements
  • Divi Header Transparent Menu
  • Divi Builder Not Working With Cloudflare CDN
  • Divi Visual Builder Not Saving Changes

Recent Comments

  • Jackie on How to Fix The Jumping Header Issue Divi Builder
  • Kate on Divi Builder Not Working With Cloudflare CDN
  • Mimi Cartee on Can’t Change The WordPress Admin Email Address

Archives

  • November 2021
  • June 2021
  • May 2021
  • March 2021
  • January 2021
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • March 2020
  • October 2019
  • September 2019
  • May 2019

Categories

  • Digital Marketing
  • Digital Marketing During Covid-19
  • Digital Technology
  • Divi Builder Resources
  • Divi Builder Tutorials
  • Gravity Forms
  • Gravity Forms Snippets
  • Local SEO
  • Social Media Marketing
  • Social Media Trends 2021
  • Uncategorized
  • WooCommerce Snippets
  • WordPress Code
  • WordPress Experts
  • WordPress Plugins
  • WordPress Technology
  • WordPress Themes
  • WordPress Troubleshooting

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2023 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Manage Cookie Consent
We use cookies to optimize our website and our service.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
Preferences
{title} {title} {title}