150 lines
6.7 KiB
PHP
150 lines
6.7 KiB
PHP
<?php
|
|
|
|
// If this file is called directly, abort.
|
|
if( !defined('ABSPATH'))
|
|
{
|
|
die('Nothing to see here...');
|
|
}
|
|
|
|
// function to check if the Out of office is active
|
|
function out_of_office_for_woo_is_active(){
|
|
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
|
|
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
|
|
$ooo_woo_is_active = esc_attr(get_option( 'ooo_woo_is_active', '' ));
|
|
$tdate = strtotime(gmdate("Y-m-d"));
|
|
$sdate = strtotime($ooo_woo_start_date);
|
|
$edate = strtotime($ooo_woo_end_date);
|
|
|
|
if ($ooo_woo_is_active == "Active") {
|
|
return true;
|
|
} elseif (($ooo_woo_is_active == "Automatic") && ($tdate >= $sdate) && ($tdate <= $edate)){
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// function to dinamically add the start and end date to the out of office message
|
|
function out_of_office_for_woo_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', 'out_of_office_for_woo_show_in_order_confirmation_email', 20 );
|
|
add_action( 'woocommerce_email_header', 'out_of_office_for_woo_show_in_order_confirmation_email', 20 );
|
|
|
|
function out_of_office_for_woo_show_in_order_confirmation_email( $order ) {
|
|
$ooo_woo_show_in_order_confirmation_email = esc_attr(get_option( 'ooo_woo_show_in_order_confirmation_email', '' ));
|
|
|
|
if ((out_of_office_for_woo_is_active()) && ($ooo_woo_show_in_order_confirmation_email == "Yes")) {
|
|
$ooo_woo_message = esc_attr(get_option( 'ooo_woo_message', '' ));
|
|
$ooo_woo_title = esc_attr(get_option( 'ooo_woo_title', '' ));
|
|
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
|
|
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
|
|
$ooo_woo_message_compiled = out_of_office_for_woo_include_dates_in_message($ooo_woo_start_date, $ooo_woo_end_date, $ooo_woo_message);
|
|
|
|
?>
|
|
<table id="out_of_office_for_woo_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 echo esc_html( $ooo_woo_title) ; ?>
|
|
</h2>
|
|
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
|
|
<p>
|
|
<?php echo wp_kses_post ( wpautop($ooo_woo_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', 'out_of_office_for_woo_show_on_shopping_cart_page', 20 );
|
|
|
|
function out_of_office_for_woo_show_on_shopping_cart_page( $order ) {
|
|
$ooo_woo_show_on_shopping_cart_page = esc_attr(get_option( 'ooo_woo_show_on_shopping_cart_page', '' ));
|
|
|
|
if ((out_of_office_for_woo_is_active()) && ($ooo_woo_show_on_shopping_cart_page == "Yes")) {
|
|
$ooo_woo_message = esc_attr(get_option( 'ooo_woo_message', '' ));
|
|
$ooo_woo_title = esc_attr(get_option( 'ooo_woo_title', '' ));
|
|
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
|
|
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
|
|
$ooo_woo_message_compiled = out_of_office_for_woo_include_dates_in_message($ooo_woo_start_date, $ooo_woo_end_date, $ooo_woo_message);
|
|
?>
|
|
|
|
<hr>
|
|
<h1>
|
|
<?php echo esc_html( $ooo_woo_title ) ; ?>
|
|
</h1>
|
|
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
|
|
<p>
|
|
<?php echo wp_kses_post( ( wpautop($ooo_woo_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', 'out_of_office_for_woo_show_on_check_out_page', 20 );
|
|
|
|
function out_of_office_for_woo_show_on_check_out_page( $order ) {
|
|
$ooo_woo_show_on_checkout_page = esc_attr(get_option( 'ooo_woo_show_on_checkout_page', '' ));
|
|
|
|
if ((out_of_office_for_woo_is_active()) && ($ooo_woo_show_on_checkout_page == "Yes")) {
|
|
$ooo_woo_message = esc_attr(get_option( 'ooo_woo_message', '' ));
|
|
$ooo_woo_title = esc_attr(get_option( 'ooo_woo_title', '' ));
|
|
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
|
|
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
|
|
$ooo_woo_message_compiled = out_of_office_for_woo_include_dates_in_message($ooo_woo_start_date, $ooo_woo_end_date, $ooo_woo_message);
|
|
?>
|
|
|
|
<hr>
|
|
<h1>
|
|
<?php echo esc_html( $ooo_woo_title, 'out-of-office-for-woo' ) ; ?>
|
|
</h1>
|
|
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
|
|
<p>
|
|
<?php echo wp_kses_post( ( wpautop($ooo_woo_message_compiled) ) ); ?>
|
|
</p>
|
|
<hr style="border: 0; border-top: 1px solid #8c8c8c; border-bottom: 1px solid #fff;">
|
|
|
|
<?php
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
add_action('wp_head', 'out_of_office_for_woo_show_on_top_bar');
|
|
function out_of_office_for_woo_show_on_top_bar()
|
|
{
|
|
if ((out_of_office_for_woo_is_active()) && ($ooo_woo_show_top_bar == "Yes")) {
|
|
$ooo_woo_message = esc_attr(get_option( 'ooo_woo_message', '' ));
|
|
$ooo_woo_title = esc_attr(get_option( 'ooo_woo_title', '' ));
|
|
$ooo_woo_start_date = esc_attr(get_option( 'ooo_woo_start_date', '' ));
|
|
$ooo_woo_end_date = esc_attr(get_option( 'ooo_woo_end_date', '' ));
|
|
$ooo_woo_message_compiled = out_of_office_for_woo_include_dates_in_message($ooo_woo_start_date, $ooo_woo_end_date, $ooo_woo_message);
|
|
|
|
?>
|
|
<div id="out_of_office_for_woo_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( $ooo_woo_title, 'out-of-office-for-woo' ) ; ?>: </strong>
|
|
<?php echo ( $ooo_woo_message_compiled ) ; ?>
|
|
|
|
</div>
|
|
<?php
|
|
}
|
|
}
|
|
*/
|