Initial Commit: first running version of the plugin

This commit is contained in:
2025-02-19 19:57:05 +01:00
parent 4d059fc0fe
commit 72ab197abc
7 changed files with 535 additions and 0 deletions

View File

@@ -0,0 +1,249 @@
<?php
// function woo_out_of_office_options()
// {
// $options = [];
// $options['start_date'] = '2024-01-01';
// $options['end_date'] = '2024-01-02';
// $options['title'] = 'We are on vacation!';
// $options['message'] = 'Between {start_date} and {end_date} we will not process any orders';
// $options['active'] = 'conditional';
// $options['show_in_order_confirmation_email'] = 'yes';
// $options['show_on_shopping_cart_page'] = 'yes';
// $options['show_on_checkout_page'] = 'yes';
// if ( !get_option( 'woo_out_of_office_option' ) )
// {
// add_option('woo_out_of_office_option', $options);
// }
// update_option('woo_out_of_office_option',$options);
// }
function woo_out_of_office_options_init()
{
add_settings_section(
'woo-out-of-office-section', //id of the options section
'Woo Out of Office Settings', //title to be displayed
'', //callback function to be called when opening section
'woo-out-of-office-page' // page on which to display the section, this should be the same as the slug used in add_submenu_page()
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_start_date'
);
add_settings_field(
'woo-ooo-start-date', // id of the settings field
'Start Date of the Out of Office', // title
'woo_out_of_office_options_cb_start_date', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_end_date'
);
add_settings_field(
'woo-ooo-end-date', // id of the settings field
'End Date of the Out of Office', // title
'woo_out_of_office_options_cb_end_date', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_title'
);
add_settings_field(
'woo-ooo-title', // id of the settings field
'Title for the Out of Office message', // title
'woo_out_of_office_options_cb_title', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_message'
);
add_settings_field(
'woo-ooo-message', // id of the settings field
'Message for the Out of Office', // title
'woo_out_of_office_options_cb_message', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_is_active'
);
add_settings_field(
'woo-ooo-is-active', // id of the settings field
'How should Out of Office be activated', // title
'woo_out_of_office_options_cb_is_active', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_show_in_order_confirmation_email'
);
add_settings_field(
'woo_ooo_show_in_order_confirmation_email', // id of the settings field
'Show message in the order confirmation Email', // title
'woo_out_of_office_options_cb_show_in_order_confirmation_email', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_show_on_shopping_cart_page'
);
add_settings_field(
'woo_ooo_show_on_shopping_cart_page', // id of the settings field
'Show message on the Shopping Cart page', // title
'woo_out_of_office_options_cb_show_on_shopping_cart_page', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_show_on_checkout_page'
);
add_settings_field(
'woo_ooo_show_on_checkout_page', // id of the settings field
'Show message on the Checkout page', // title
'woo_out_of_office_options_cb_show_on_checkout_page', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
register_setting(
'woo-out-of-office-page', //option group ???? check if this should be the slug or the option section id!!!
'woo_ooo_show_top_bar'
);
add_settings_field(
'woo_ooo_show_top_bar', // id of the settings field
'Show a top bar with the out of office', // title
'woo_out_of_office_options_cb_show_top_bar', // callback function
'woo-out-of-office-page', // page on which settings display
'woo-out-of-office-section' // section on which to show the settings
);
}
function woo_out_of_office_options_cb_start_date()
{
$woo_ooo_start_date = esc_attr(get_option( 'woo_ooo_start_date', '' ));
?>
<div>
<input id="title" type="date" name="woo_ooo_start_date" value="<?php echo $woo_ooo_start_date; ?>">
</div>
<?php
}
function woo_out_of_office_options_cb_end_date()
{
$woo_ooo_end_date = esc_attr(get_option( 'woo_ooo_end_date', '' ));
?>
<div>
<input id="title" type="date" name="woo_ooo_end_date" value="<?php echo $woo_ooo_end_date; ?>">
</div>
<?php
}
function woo_out_of_office_options_cb_title()
{
$woo_ooo_title = esc_attr(get_option( 'woo_ooo_title', '' ));
?>
<div>
<input id="title" type="text" name="woo_ooo_title" value="<?php echo $woo_ooo_title; ?>">
</div>
<?php
}
function woo_out_of_office_options_cb_message()
{
$woo_ooo_message = esc_attr(get_option( 'woo_ooo_message', '' ));
?>
<div>
<textarea id="title" name="woo_ooo_message" rows="6" cols="80"><?php echo $woo_ooo_message; ?></textarea>
<br>
Use <strong><i>[StartDate]</i></strong> and <strong><i>[EndDate]</i></strong> as shortcodes within the text in order to incorporate the actual dates.
<br>
For example: "We are between [StartDate] and [EndDate] on vacation :)"
<br>
The result is displayed below :)
</div>
<?php
}
function woo_out_of_office_options_cb_is_active()
{
$woo_ooo_is_active = esc_attr(get_option( 'woo_ooo_is_active', '' ));
//
?>
<div>
<input type="radio" id="title" name="woo_ooo_is_active" value="Automatic" <?php if ($woo_ooo_is_active == "Automatic") {echo('checked');}?>>
<label for="Automatic">Automatic (Out of office will be active only in the period between StartDate and EndDate)</label><br>
<input type="radio" id="title" name="woo_ooo_is_active" value="Active" <?php if ($woo_ooo_is_active == "Active") {echo('checked');}?>>
<label for="Active">Active (Out of office is always active - ON)</label><br>
<input type="radio" id="title" name="woo_ooo_is_active" value="Inactive" <?php if ($woo_ooo_is_active == "Inactive") {echo('checked');}?>>
<label for="Inactive">Inactive (Out of office is inactive - OFF)</label><br>
</div>
<?php
}
function woo_out_of_office_options_cb_show_in_order_confirmation_email()
{
$woo_ooo_show_in_order_confirmation_email = esc_attr(get_option( 'woo_ooo_show_in_order_confirmation_email', '' ));
//
?>
<div>
<input type="radio" id="title" name="woo_ooo_show_in_order_confirmation_email" value="Yes" <?php if ($woo_ooo_show_in_order_confirmation_email == "Yes") {echo('checked');}?>>
<label for="Yes">Yes</label><br>
<input type="radio" id="title" name="woo_ooo_show_in_order_confirmation_email" value="No" <?php if ($woo_ooo_show_in_order_confirmation_email == "No") {echo('checked');}?>>
<label for="No">No</label><br>
</div>
<?php
}
function woo_out_of_office_options_cb_show_on_shopping_cart_page()
{
$woo_ooo_show_on_shopping_cart_page = esc_attr(get_option( 'woo_ooo_show_on_shopping_cart_page', '' ));
//
?>
<div>
<input type="radio" id="title" name="woo_ooo_show_on_shopping_cart_page" value="Yes" <?php if ($woo_ooo_show_on_shopping_cart_page == "Yes") {echo('checked');}?>>
<label for="Yes">Yes</label><br>
<input type="radio" id="title" name="woo_ooo_show_on_shopping_cart_page" value="No" <?php if ($woo_ooo_show_on_shopping_cart_page == "No") {echo('checked');}?>>
<label for="No">No</label><br>
</div>
<?php
}
function woo_out_of_office_options_cb_show_on_checkout_page()
{
$woo_ooo_show_on_checkout_page = esc_attr(get_option( 'woo_ooo_show_on_checkout_page', '' ));
//
?>
<div>
<input type="radio" id="title" name="woo_ooo_show_on_checkout_page" value="Yes" <?php if ($woo_ooo_show_on_checkout_page == "Yes") {echo('checked');}?>>
<label for="Yes">Yes</label><br>
<input type="radio" id="title" name="woo_ooo_show_on_checkout_page" value="No" <?php if ($woo_ooo_show_on_checkout_page == "No") {echo('checked');}?>>
<label for="No">No</label><br>
</div>
<?php
}
function woo_out_of_office_options_cb_show_top_bar()
{
$woo_ooo_show_top_bar = esc_attr(get_option( 'woo_ooo_show_top_bar', '' ));
//
?>
<div>
<input type="radio" id="title" name="woo_ooo_show_top_bar" value="Yes" <?php if ($woo_ooo_show_top_bar == "Yes") {echo('checked');}?>>
<label for="Yes">Yes</label><br>
<input type="radio" id="title" name="woo_ooo_show_top_bar" value="No" <?php if ($woo_ooo_show_top_bar == "No") {echo('checked');}?>>
<label for="No">No</label><br>
<br>
<strong>Not yet implemented</strong>
</div>
<?php
}
//add_action('admin_init', 'woo_out_of_office_options');