Last active
May 17, 2024 11:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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