Skip to content

Instantly share code, notes, and snippets.

@blogjunkie
Created May 8, 2020 14:17
Show Gist options
  • Save blogjunkie/c3f97eb37900aa45a94bae923647dc87 to your computer and use it in GitHub Desktop.
Save blogjunkie/c3f97eb37900aa45a94bae923647dc87 to your computer and use it in GitHub Desktop.
Replace Buy Now with Learn More on some product categories
<?php
add_action( 'woocommerce_before_shop_loop', 'onn_modify_affiliates_category_buttons' );
function onn_modify_affiliates_category_buttons() {
if ( is_product_category() ){
global $wp_query;
// Get current product category
$cat = $wp_query->get_queried_object();
// If this is the Affiliates category...
if ( 'affiliates' == $cat->slug ) {
// Remove add to cart button
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
// Extra step to remove add to cart button for Astra theme
add_filter( 'astra_woo_shop_product_structure', function($shop_structure) {
$new_shop_structure = array_diff( $shop_structure, array('add_cart') );
return $new_shop_structure;
});
// Add the Learn More button
add_action( 'woocommerce_after_shop_loop_item', function() {
echo '<a href="' . get_permalink( get_the_ID() ) . '" class="button" aria-label="Learn More">Learn More</a>';
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment