I need a little help with my very first plugin. It's not that big a plugin and consists of a small settings page with 3 text fields that display on the woocommerce checkout page with some css.
I'm stuck at one bit though. I want to display the fields only if they have something to display. At the moment when they're empty, it will display the background css styling and still behave on click. I just want to have it not display if the field is empty.
In the public folder of the plugin I've got this. I hope someone can shed some light on it for me
// first button below billing form
add_action('woocommerce_after_checkout_billing_form', 'show_my_message');
function show_my_message() {
$wc_checkout_message_settings = get_option('wc_checkout_message_settings');
echo $wc_checkout_message_settings[wc_checkout_message_text_field_0];
echo '<br>';
echo $wc_checkout_message_settings[wc_checkout_message_text_field_1];
}
// second set of buttons linking to payment only section
add_action('woocommerce_review_order_before_payment', 'show_new_message');
function show_new_message(){
$wc_checkout_message_settings = get_option('wc_checkout_message_settings');
echo $wc_checkout_message_settings[wc_checkout_message_text_field_2];
}
I need a little help with my very first plugin. It's not that big a plugin and consists of a small settings page with 3 text fields that display on the woocommerce checkout page with some css.
I'm stuck at one bit though. I want to display the fields only if they have something to display. At the moment when they're empty, it will display the background css styling and still behave on click. I just want to have it not display if the field is empty.
In the public folder of the plugin I've got this. I hope someone can shed some light on it for me
// first button below billing form
add_action('woocommerce_after_checkout_billing_form', 'show_my_message');
function show_my_message() {
$wc_checkout_message_settings = get_option('wc_checkout_message_settings');
echo $wc_checkout_message_settings[wc_checkout_message_text_field_0];
echo '<br>';
echo $wc_checkout_message_settings[wc_checkout_message_text_field_1];
}
// second set of buttons linking to payment only section
add_action('woocommerce_review_order_before_payment', 'show_new_message');
function show_new_message(){
$wc_checkout_message_settings = get_option('wc_checkout_message_settings');
echo $wc_checkout_message_settings[wc_checkout_message_text_field_2];
}
Do echo inside an if statement.
function show_my_message() {
$settings = get_option('wc_checkout_message_settings');
//Check if the array is set
if( isset($settings['wc_checkout_message_text_field_0']) && !empty($settings['wc_checkout_message_text_field_0']) ){
echo $settings['wc_checkout_message_text_field_0'];
}
//Check the other value and show it
if(isset($settings['wc_checkout_message_text_field_1']) && !empty($settings['wc_checkout_message_text_field_1']) ){
echo $settings['wc_checkout_message_text_field_1'];
}
}