Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active May 17, 2024 11:50
Show Gist options
  • Save braddalton/df5fc3e2688ff8033e84ae1c06d32143 to your computer and use it in GitHub Desktop.
Save braddalton/df5fc3e2688ff8033e84ae1c06d32143 to your computer and use it in GitHub Desktop.
Conditional Button Text for Out of Stock Products and Specific Attribute Full Code https://wpsites.net/?p=115979
add_filter('woocommerce_product_add_to_cart_text', 'custom_combined_add_to_cart_button_text', 10, 2);
add_filter('woocommerce_product_single_add_to_cart_text', 'custom_combined_add_to_cart_button_text', 10, 2);
function custom_combined_add_to_cart_button_text($text, $product) {
if ( ! $product->is_in_stock()) {
return __('Out of Stock', 'woocommerce');
} else {
$attributes = $product->get_attributes();
if (isset($attributes['pa_custom_attribute'])) {
$terms = wp_get_post_terms($product->get_id(), 'pa_custom_attribute');
foreach ($terms as $term) {
if ($term->slug == 'get_quote') {
return __('Get Quote', 'woocommerce');
}
}
}
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment