Custom Call to order button

I am trying to add a custom button on my product page if it belongs in a certain category. For some reason the code is not working, I have used it on some of my other sites so I know it is good code. I tried deactivating all my plugins as well as changing my theme to see if either of those had conflicts but it still was not working. Here is my code:

add_action( 'woocommerce_before_single_variation', 'lp_call_to_order_button' );
 
function lp_call_to_order_button() {  
  	if ( is_product() && has_term( 'equipment', 'product_cat' ) ) {
		//Show Link
		?>
			<a href="tel:(903)939-3369" class="x-btn x-btn-global"><i class="x-icon mvn mln mrs x-icon-phone" data-x-icon="" aria-hidden="true"></i> Call to Order</a>
		<?php
	}	
}

Hi There,

Your website is down right now.

Could you please provide us with your FTP account as well?

Thanks.

Seems to be up now, not sure what happened.

Hi there,

There is a problem with your term/category, notice that even your var_dump() display false, and if you check the category below the button, it only shows Carbon Fiber and there is no Equipment.

Another thing is if you go to Admin > Products > Categories, the Equipment shows 1 post, while Carbon Fiber has 0 post. In which contradict the category assignment being displayed in the front.

Something is wrong with your system, maybe related to database, you should contact a woocommerce developer to check this. I also suggest to do a clean installation in a staging and test your code there, your code works but the condition is just returning false because it detects that Equipment is not your product term.

Thanks!

I had it setup right, I think maybe @thai changed some settings. I changed it back but it is still not showing up.

ok, I figured it out, it was a few things. First i was trying to hide the equipment category with another snippet but it was causing some issues so i updated it to only load on shop pages, the working code is below.

// Remove category slug from shop

add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
function get_subcategory_terms( $terms, $taxonomies, $args ) {
 $new_terms = array();
 // if a product category and on the shop page
 if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
 foreach ( $terms as $key => $term ) {
 if ( ! in_array( $term->slug, array( 'equipment' ) ) ) {
 $new_terms[] = $term;
 }
 }
 $terms = $new_terms;
 }
 return $terms;
}

My next issue was i was not adding a price as i want customers to call for a quote so my custom call button code from my first post was failing since the price was never listed. Here is my updated code:

add_action( 'woocommerce_single_product_summary', 'lp_call_to_order_button' );

function lp_call_to_order_button() {  
  	if ( is_product() && has_term( 'equipment', 'product_cat' ) ) {
		//Show Link
		?>
			<a href="tel:(903)939-3369" class="x-btn x-btn-global"><i class="x-icon mvn mln mrs x-icon-phone" data-x-icon="" aria-hidden="true"></i> Call to Order</a>
		<?php
	}	

Maybe it can help someone, thanks for helping figure out what i did wrong!

Hello There,

Thanks for updating in! We are just glad that you have figured it out a way to correct the said issue.
We really appreciate for letting us know!

Best Regards.