Skip to content

Instantly share code, notes, and snippets.

@frankschrijvers
Last active July 17, 2021 04:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frankschrijvers/514cf1aa0fe496c83dcc19012191b942 to your computer and use it in GitHub Desktop.
Save frankschrijvers/514cf1aa0fe496c83dcc19012191b942 to your computer and use it in GitHub Desktop.
Change add to cart button text per category
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Change add to cart button text per category
add_filter( 'woocommerce_product_single_add_to_cart_text', 'wps_custom_cart_button_text' );
function wps_custom_cart_button_text() {
global $product;
$terms = get_the_terms( $product->ID, 'product_cat' );
foreach ($terms as $term) {
$product_cat = $term->slug;
break;
}
switch($product_cat) {
case 'clothing';
return __('Order your Clothes', 'your_theme_text_domain' );
default;
return __( 'Order now', 'your_theme_text_domain' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment