Needing to add a conditional PHP statement for woocommerce webhooks

So in a nutshell I have a code that checks if an item is listed with a price or not on my website. If there is no price, or the price is 0 it currently shows “Call # to Order”

My problem is I need that clickable phone number to change depending on where a product is located. For example if my product is in china, I need my current php code to detect its location based on the products category, then display the correct number for the china location.

I can’t figure out how to get this thing working and I think it’s just my php conditionals or maybe the woocommerce hook I’m using is wrong.

Any assistance would be greatly appreciated.

<?php add_action( ‘woocommerce_product_options_general_product_data’, ‘custom_general_product_data_custom_fields’ );
/**
* Add `Not Ready to Sell` field in the Product data’s General tab.
*/
function custom_general_product_data_custom_fields() {
// Checkbox.
woocommerce_wp_checkbox(
array(
‘id’ => ‘_not_ready_to_sell’,
‘wrapper_class’ => ‘show_if_simple’,
‘label’ => __( ‘Call for Price’, ‘woocommerce’ ),
‘description’ => __( ”, ‘woocommerce’ )
)
);
}

add_action( ‘woocommerce_process_product_meta’, ‘custom_save_general_proddata_custom_fields’ );
/**
* Save the data values from the custom fields.
* @param int $post_id ID of the current product.
*/
function custom_save_general_proddata_custom_fields( $post_id ) {
// Checkbox.
$woocommerce_checkbox = isset( $_POST[‘_not_ready_to_sell’] ) ? ‘yes’ : ‘no’;
update_post_meta( $post_id, ‘_not_ready_to_sell’, $woocommerce_checkbox );
}

add_filter( ‘woocommerce_is_purchasable’, ‘custom_woocommerce_set_purchasable’ );
/**
* Mark “Not ready to sell” products as not purchasable.
*/
function custom_woocommerce_set_purchasable() {
$not_ready_to_sell = get_post_meta( get_the_ID(), ‘_not_ready_to_sell’, true );

return ( ‘yes’ === $not_ready_to_sell ? false : true );
}

add_filter( ‘woocommerce_product_add_to_cart_text’, ‘custom_product_add_to_cart_text’ );
/**
* Change “Read More” button text for non-purchasable products.
*/
function custom_product_add_to_cart_text() {
$not_ready_to_sell = get_post_meta( get_the_ID(), ‘_not_ready_to_sell’, true );

if ( ‘yes’ === $not_ready_to_sell ) {
return __( ‘Call to Order’, ‘woocommerce’ );
} else {
return __( ‘Add to cart’, ‘woocommerce’ );
}
}

add_action( ‘woocommerce_single_product_summary’, ‘custom_woocommerce_call_to_order_text’, 30 );
/**
* Add calling instructions for non-purchasable products.
*/
function custom_woocommerce_call_to_order_text() {
$not_ready_to_sell = get_post_meta( get_the_ID(), ‘_not_ready_to_sell’, true );

if ( ‘yes’ === $not_ready_to_sell ) {

***//I swear this is where the condition should start but i keep breaking the code***

echo ‘<p class=”content-box-blue”>Call to order this product.</p> <strong><a href=”tel:#######”>(###) ###-####</a></strong>’;
}

}

Read more here:: Needing to add a conditional PHP statement for woocommerce webhooks

Leave a Reply

Your email address will not be published. Required fields are marked *