Initial Commit: first running version of the plugin
This commit is contained in:
143
includes/woo-out-of-office-functions.php
Normal file
143
includes/woo-out-of-office-functions.php
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user