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,143 @@
<?php
// function to check if the Out of office is active
function woo_out_of_office_is_active(){
$woo_ooo_start_date = esc_attr(get_option( 'woo_ooo_start_date', '' ));
$woo_ooo_end_date = esc_attr(get_option( 'woo_ooo_end_date', '' ));
$woo_ooo_is_active = esc_attr(get_option( 'woo_ooo_is_active', '' ));
$tdate = strtotime(date("Y-m-d"));
$sdate = strtotime($woo_ooo_start_date);
$edate = strtotime($woo_ooo_end_date);
if ($woo_ooo_is_active == "Active") {
return true;
} elseif (($woo_ooo_is_active == "Automatic") && ($tdate >= $sdate) && ($tdate <= $edate)){
return true;
} else {
return false;
}
}
function woo_out_of_office_include_dates_in_message($start_date, $end_date, $message){
$message_compiled = str_replace("[StartDate]", wp_date(get_option('date_format'), strtotime($start_date)), $message);
$message_compiled = str_replace("[EndDate]", wp_date(get_option('date_format'), strtotime($end_date)), $message_compiled);
return $message_compiled;
}
// function to add the out of office message to the order confirmation email
add_action( 'woocommerce_email_before_order_table', 'woo_out_of_office_show_in_order_confirmation_email', 20 );
function woo_out_of_office_show_in_order_confirmation_email( $order ) {
$woo_ooo_show_in_order_confirmation_email = esc_attr(get_option( 'woo_ooo_show_in_order_confirmation_email', '' ));
if ((woo_out_of_office_is_active()) && ($woo_ooo_show_in_order_confirmation_email == "Yes")) {
$woo_ooo_message = esc_attr(get_option( 'woo_ooo_message', '' ));
$woo_ooo_title = esc_attr(get_option( 'woo_ooo_title', '' ));
$woo_ooo_start_date = esc_attr(get_option( 'woo_ooo_start_date', '' ));
$woo_ooo_end_date = esc_attr(get_option( 'woo_ooo_end_date', '' ));
$woo_ooo_message_compiled = woo_out_of_office_include_dates_in_message($woo_ooo_start_date, $woo_ooo_end_date, $woo_ooo_message);
?>
<table id="woo_out_of_office_show_in_order_confirmation_email" cellspacing="0" cellpadding="0" style="width: 100%; vertical-align: top; margin-bottom: 40px; margin-top: 20px; padding: 0; border= 2px solid black; border-collapse: collapse;">
<tr>
<td style="text-align: left; border: 0; padding: 0;" valign="top">
<hr>
<h2>
<?php esc_html_e( $woo_ooo_title ) ; ?>
</h2>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<p>
<?php echo ( wpautop($woo_ooo_message_compiled) ) ; ?>
</p>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
</td>
</tr>
</table>
<?php
}
}
// function to add the out of office message to the shopping cart page
add_action( 'woocommerce_before_cart_table', 'woo_out_of_office_show_on_shopping_cart_page', 20 );
function woo_out_of_office_show_on_shopping_cart_page( $order ) {
$woo_ooo_show_on_shopping_cart_page = esc_attr(get_option( 'woo_ooo_show_on_shopping_cart_page', '' ));
if ((woo_out_of_office_is_active()) && ($woo_ooo_show_on_shopping_cart_page == "Yes")) {
$woo_ooo_message = esc_attr(get_option( 'woo_ooo_message', '' ));
$woo_ooo_title = esc_attr(get_option( 'woo_ooo_title', '' ));
$woo_ooo_start_date = esc_attr(get_option( 'woo_ooo_start_date', '' ));
$woo_ooo_end_date = esc_attr(get_option( 'woo_ooo_end_date', '' ));
$woo_ooo_message_compiled = woo_out_of_office_include_dates_in_message($woo_ooo_start_date, $woo_ooo_end_date, $woo_ooo_message);
?>
<hr>
<h1>
<?php esc_html_e( $woo_ooo_title ) ; ?>
</h1>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<p>
<?php echo ( wpautop($woo_ooo_message_compiled) ) ; ?>
</p>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<?php
}
}
// function to add the out of office message to the check out page
add_action( 'woocommerce_before_checkout_form', 'woo_out_of_office_show_on_check_out_page', 20 );
function woo_out_of_office_show_on_check_out_page( $order ) {
$woo_ooo_show_on_checkout_page = esc_attr(get_option( 'woo_ooo_show_on_checkout_page', '' ));
if ((woo_out_of_office_is_active()) && ($woo_ooo_show_on_checkout_page == "Yes")) {
$woo_ooo_message = esc_attr(get_option( 'woo_ooo_message', '' ));
$woo_ooo_title = esc_attr(get_option( 'woo_ooo_title', '' ));
$woo_ooo_start_date = esc_attr(get_option( 'woo_ooo_start_date', '' ));
$woo_ooo_end_date = esc_attr(get_option( 'woo_ooo_end_date', '' ));
$woo_ooo_message_compiled = woo_out_of_office_include_dates_in_message($woo_ooo_start_date, $woo_ooo_end_date, $woo_ooo_message);
?>
<hr>
<h1>
<?php esc_html_e( $woo_ooo_title ) ; ?>
</h1>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<p>
<?php echo ( wpautop($woo_ooo_message_compiled) ) ; ?>
</p>
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
<?php
}
}
add_action('wp_head', 'woo_out_of_office_show_on_top_bar');
function woo_out_of_office_show_on_top_bar()
{
if ((woo_out_of_office_is_active()) && ($woo_ooo_show_top_bar == "Yes")) {
$woo_ooo_message = esc_attr(get_option( 'woo_ooo_message', '' ));
$woo_ooo_title = esc_attr(get_option( 'woo_ooo_title', '' ));
$woo_ooo_start_date = esc_attr(get_option( 'woo_ooo_start_date', '' ));
$woo_ooo_end_date = esc_attr(get_option( 'woo_ooo_end_date', '' ));
$woo_ooo_message_compiled = woo_out_of_office_include_dates_in_message($woo_ooo_start_date, $woo_ooo_end_date, $woo_ooo_message);
?>
<div id="woo_out_of_office_top_bar" style="background: #e1e1e1; color: #333333; font-size:16px; top: 0px; left: 0px; width: 100% !important; padding: 10px 0px; text-align: center;" >
<strong><?php esc_html_e( $woo_ooo_title ) ; ?>: </strong>
<?php echo ( $woo_ooo_message_compiled ) ; ?>
</div>
<?php
}
}

View File

@@ -0,0 +1,42 @@
<?php
// Hook into 'admin_menu' action to add our custom menu page
add_action('admin_menu', 'woo_out_of_office_tools_submenu');
function woo_out_of_office_tools_submenu()
{
add_submenu_page(
'options-general.php', // Parent menu slug (Tools)
'Woo Out of Office Settings Page', // Page title
'Woo Out of Office', // Menu title
'manage_options', // Capability of the user to see this page
'woo-out-of-office-page', // Menu slug of the settings page
'woo_out_of_office_tools_submenu_page' // Function to display the page content
);
add_action('admin_init', 'woo_out_of_office_options_init');
}
// Function to output the content of our custom sub-menu page
function woo_out_of_office_tools_submenu_page() {
//Double check user capabilities
if ( !current_user_can('manage_options') ) {
return;
}
//echo("test");
//echo(plugin_basename( __FILE__ ));
include( WOOO_DIR . 'templates/admin/settings-page.php');
}
// Add a link to your settings page in your plugin
function woo_out_of_office_add_settings_link( $links ) {
$url = get_admin_url( ) . "options-general.php?page=woo-out-of-office-page";
$settings_link = '<a href="' . $url . '">' . __('Settings', 'woo-out-of-office-page') . '</a>';
$links[] = $settings_link;
// $settings_link = '<a href="options-general.php?page=woo-out-of-office-page">' . __( 'Settings','woo-out-of-office-page' ) . '</a>';
// array_push( $links, $settings_link );
return $links;
}
$filter_name = "plugin_action_links_" . WOOO_BASENAME;
add_filter( $filter_name, 'woo_out_of_office_add_settings_link' );

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');