id = 'acr_settings';
$this->label = __( 'Cart Recovery', 'advanced-cart-recovery' );
// Advanced Cart Recovery tab
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 30 );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'acrOutput' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'acrSave' ) );
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
add_filter( 'woocommerce_get_sections_' . $this->id, array( $this, 'acrGetSections' ) );
add_action( 'woocommerce_admin_field_acr_help_resources' , array( $this , 'acrRenderHelpResources' ) );
add_action( 'woocommerce_admin_field_acr_email_schedules' , array( $this, 'acrRenderACREmailSchedules' ) );
add_action( 'woocommerce_admin_field_acr_blacklist_emails' , array( $this, 'acrRenderACRBlacklistEmails' ) );
// Show upsell graphics
if( apply_filters( 'acr_show_upsells', true ) )
add_action( 'woocommerce_admin_field_acr_upsell' , array( $this , 'acrRenderUpsellGraphics' ) );
add_action( 'woocommerce_admin_field_acr_button', array( $this, 'acrRenderButton' ) );
$acrEmails = ACR_Emails::getInstance();
$this->acrEmailDefault = $acrEmails->acrDefaultTemplate;
$this->acrOrderStatuses = apply_filters( 'acr_general_statuses',
array(
'wc-pending' => __( 'Pending Payment', 'advanced-cart-recovery' ),
'wc-cancelled' => __( 'Cancelled', 'advanced-cart-recovery' ),
'wc-on-hold' => __( 'On Hold', 'advanced-cart-recovery' ),
'wc-failed' => __( 'Failed', 'advanced-cart-recovery' )
)
);
$this->acrOrderStatusesConsideredCompleted = apply_filters( 'acr_general_statuses_considered_completed',
array(
'wc-completed' => __( 'Completed', 'advanced-cart-recovery' ),
'wc-processing' => __( 'Processing', 'advanced-cart-recovery' )
)
);
// Email Schedules
add_action( 'woocommerce_admin_field_acr_email_wrap_wc_header_footer_field', array( $this, 'acrRenderWrapWooHeaderFooter' ) );
add_action( 'woocommerce_admin_field_acr_content_wysiwyg', array( $this, 'acrRenderEmailContentWYSIWYG' ) );
add_action( 'woocommerce_admin_field_acr_schedule_buttons', array( $this, 'acrRenderSchedulesButtons' ) );
do_action( 'acr_settings_constructor' );
}
/**
* Get sections.
*
* @return array
* @since 1.0.0
*/
public function acrGetSections() {
$sections = array(
'' => __( 'General', 'advanced-cart-recovery' ),
'acr_settings_email_schedules' => __( 'Email Schedules', 'advanced-cart-recovery' ),
'acr_blacklist_emails_section' => __( 'Blacklist Emails', 'advanced-cart-recovery' ),
'acr_settings_help_section' => __( 'Help', 'advanced-cart-recovery' ),
);
return apply_filters( 'acr_get_sections_' . $this->id, $sections );
}
/**
* Output the settings.
*
* @since 1.0.0
*/
public function acrOutput() {
global $current_section;
$settings = $this->acrGetSettings( $current_section );
WC_Admin_Settings::output_fields( $settings );
}
/**
* Save settings.
*
* @since 1.0.0
*/
public function acrSave() {
global $current_section;
$settings = $this->acrGetSettings( $current_section );
WC_Admin_Settings::save_fields( $settings );
}
/**
* Get settings array.
*
* @param string $current_section
*
* @return string
* @since 1.0.0
*/
public function acrGetSettings( $current_section = '' ) {
if ( $current_section == 'acr_settings_help_section' ) {
// Help Section
$settings = apply_filters( 'acr_settings_help_section_settings', $this->acrGetHelpSectionSettings() );
if( ! isset( $_GET[ 'debug' ] ) || ( isset( $_GET[ 'debug' ] ) && $_GET[ 'debug' ] != true ) ) { ?>
acrGetEmailSchedulesSectionSettings() );
} else if ( $current_section == 'acr_blacklist_emails_section' ) {
$settings = apply_filters( 'acr_settings_blacklist_emails_section_settings', $this->acrGetBlacklistEmailsSectionSettings() );
} else {
// General Section
$settings = apply_filters( 'acr_settings_general_section_settings', $this->acrGetGeneralSectionSettings() );
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
}
/*
|--------------------------------------------------------------------------------------------------------------
| Section Settings
|--------------------------------------------------------------------------------------------------------------
*/
/**
* Get general section settings.
*
* @return array
* @since 1.0.0
*/
private function acrGetGeneralSectionSettings(){
$abandonedTime = get_option( 'acr_general_cart_abandoned_time' );
$abandonedTime = ! empty( $abandonedTime ) ? $abandonedTime : 0 ;
$abandonedStatus = get_option( 'acr_general_status_considered_abandoned' );
$setStatus = '';
foreach ( $abandonedStatus as $key => $status ) {
$status = ucwords( str_replace( '-', ' ', substr( $status, 3 ) ) );
$setStatus .= '' . $status . ' or ';
}
$setStatus = substr( $setStatus, 0, -4 );
$acrGeneralSettings = array(
array(
'title' => __( 'General Options', 'advanced-cart-recovery' ),
'type' => 'title',
'id' => 'acr_general_main_title'
),
array(
'type' => 'acr_upsell',
'id' => 'acr_upsell',
),
array(
'type' => 'sectionend',
'id' => 'acr_general_upsell_end'
),
array(
'type' => 'title',
'desc' => sprintf( __( 'Current Settings: After %1$s hours if an Order is in [ %2$s ] it is considered abandoned.', 'advanced-cart-recovery' ), $abandonedTime, $setStatus ),
'id' => 'acr_general_current_settings'
),
array(
'title' => __( 'Cart Abandoned Cut-Off Time', 'advanced-cart-recovery' ),
'type' => 'number',
'desc' => __( 'Hour(s) after which an order considered abandoned.', 'advanced-cart-recovery' ),
'desc_tip' => __( 'Default is 6 Hours.', 'advanced-cart-recovery' ),
'id' => 'acr_general_cart_abandoned_time',
'css' => 'width:60px;',
'custom_attributes' => array(
'min' => 0,
'step' => 1
)
),
array(
'title' => __( 'Abandoned Order Status', 'advanced-cart-recovery' ),
'type' => 'multiselect',
'desc' => __( 'If an order ends up in one of the selected statuses and the customer doesn\'t make an order before the cut-off time, the order will be considered as abandoned.', 'advanced-cart-recovery' ),
'desc_tip' => __( 'The list of order statuses that will be considered as abandoned carts. Default is Pending and Cancelled.' , 'advanced-cart-recovery' ),
'id' => 'acr_general_status_considered_abandoned',
'css' => 'width:350px;',
'options' => $this->acrOrderStatuses
),
array(
'title' => __( 'Complete Order Status', 'advanced-cart-recovery' ),
'type' => 'multiselect',
'desc' => __( 'If an order ends up in one of the selected statuses and the customer successfully makes an order, it should cancel all abandoned carts for that email address.', 'advanced-cart-recovery' ),
'desc_tip' => __( 'The list of order statuses that will be considered as complete orders. Default is Completed.' , 'advanced-cart-recovery' ),
'id' => 'acr_general_status_considered_completed',
'css' => 'width:350px;',
'options' => $this->acrOrderStatusesConsideredCompleted
),
array(
'title' => __( 'Cart Abandoned Forever Time', 'advanced-cart-recovery' ),
'desc' => __( 'Number of days after the final email was sent that "Not Recovered" carts will be considered abandoned forever.', 'advanced-cart-recovery' ),
'id' => 'acr_general_time_considered_cancelled',
'type' => 'text',
'default' => '7',
'desc_tip' => __( 'Default is 7 Days.', 'advanced-cart-recovery' ),
),
array(
'title' => __( 'Allow Recovery With Different Email', 'advanced-cart-recovery' ),
'type' => 'checkbox',
'desc' => __( 'Counts customers that recover the cart and use a different email during checkout.', 'advanced-cart-recovery' ),
'desc_tip' => __( 'Abandoned carts normally can only be recovered with the same email but, when enabled, this setting will allow people to checkout using a different email and the corresponding abandoned cart record will be changed to recovered.', 'advanced-cart-recovery' ),
'id' => 'acr_general_allow_recovery_with_different_email',
),
array(
'type' => 'sectionend',
'id' => 'acr_general_sectionend'
)
);
return apply_filters( 'acr_general_settings', $acrGeneralSettings );
}
/**
* Email schedule settings
*
* @return array
* @since 1.0.0
*/
public function acrGetEmailSchedulesSectionSettings(){
$acrEmailSchedulesSettings = array(
array(
'title' => __( 'Email Schedules', 'advanced-cart-recovery' ),
'type' => 'title',
'desc' => '',
'id' => 'acr_email_schedules_main_title'
),
array(
'name' => '',
'type' => 'acr_email_schedules',
'desc' => '',
'id' => 'acr_email_schedules',
),
array(
'type' => 'sectionend',
'id' => 'acr_email_schedules_sectionend'
)
);
return apply_filters( 'acr_email_schedules_settings', $acrEmailSchedulesSettings );
}
/**
* Get blacklist section settings.
*
* @return array
* @since 1.0.0
*/
private function acrGetBlacklistEmailsSectionSettings(){
$acrBlackListSettings = array(
array(
'title' => __( 'Blacklist Options', 'advanced-cart-recovery' ),
'type' => 'title',
'desc' => __( 'A list of all email addressed that have opted out of abandoned cart communication.', 'advanced-cart-recovery' ),
'id' => 'acr_help_main_title'
),
array(
'name' => '',
'type' => 'acr_blacklist_emails',
'desc' => __( 'Enter the customer or email address you want to add in the list.', 'advanced-cart-recovery' ),
'id' => 'acr_blacklist_emails',
),
array(
'type' => 'sectionend',
'id' => 'acr_blacklist_sectionend'
)
);
return apply_filters( 'acr_blacklist_settings', $acrBlackListSettings );
}
/**
* Get help section settings.
*
* @return array
* @since 1.0.0
*/
private function acrGetHelpSectionSettings(){
$acrHelpSettings = array(
array(
'title' => __( 'Help Options', 'advanced-cart-recovery' ),
'type' => 'title',
'desc' => '',
'id' => 'acr_help_main_title'
),
array(
'title' => '',
'type' => 'acr_help_resources',
'desc' => '',
'id' => 'acr_help_resources'
),
array(
'title' => __( 'Run Abandoned Cart', 'advanced-cart-recovery' ),
'type' => 'acr_button',
'desc' => sprintf( __( 'This will run the %1$s hook.', 'advanced-cart-recovery' ), ACR_ABANDONED_CART_CRON ),
'id' => 'acr_manual_run_abandoned_cart_checker',
'class' => 'button button-primary'
),
array(
'title' => __( 'Run Email Sender', 'advanced-cart-recovery' ),
'type' => 'acr_button',
'desc' => sprintf( __( 'This will send all scheduled cron emails under %1$s hook.', 'advanced-cart-recovery' ), ACR_EMAIL_SENDER_CRON ),
'id' => 'acr_manual_run_email',
'class' => 'button button-primary'
),
array(
'title' => __( 'Run Abandoned Forever', 'advanced-cart-recovery' ),
'type' => 'acr_button',
'desc' => sprintf( __( 'This will make all not-recovered carts into cancelled under %1$s hook.
( note: %2$s hook is created after an email has succesfully sent to the customer and refreshes the time everytime there are multiple emails sent.
In case the cart object is not turned to cancelld it maybe because no email has sent out yet. )', 'advanced-cart-recovery' ), ACR_CANCELLED_CART_CRON, ACR_CANCELLED_CART_CRON ),
'id' => 'acr_manual_run_cancelled_cart_checker',
'class' => 'button button-primary'
),
array(
'title' => __( 'Clear All Emails', 'advanced-cart-recovery' ),
'type' => 'acr_button',
'desc' => __( 'This will remove all scheduled cron emails.', 'advanced-cart-recovery' ),
'id' => 'acr_manual_run_clear_all_emails',
'class' => 'button button-primary'
),
array(
'title' => __( 'Clear All Abandoned Carts', 'advanced-cart-recovery' ),
'type' => 'acr_button',
'desc' => __( 'This will delete all not recovered carts. ( note: cancelled and recovered ones stay put )', 'advanced-cart-recovery' ),
'id' => 'acr_manual_run_clear_all_abandoned_carts',
'class' => 'button button-primary'
),
array(
'title' => __( 'Clean up plugin options on un-installation', 'advanced-cart-recovery' ),
'type' => 'checkbox',
'desc' => __( 'If checked, removes all plugin options when this plugin is uninstalled. Note: Also affect premium version.', 'advanced-cart-recovery' ),
'id' => 'acr_clean_plugin_options',
),
array(
'type' => 'sectionend',
'id' => 'acr_cron_sectionend'
)
);
return apply_filters( 'acr_help_settings', $acrHelpSettings );
}
/*
|--------------------------------------------------------------------------------------------------------------
| Settings
|--------------------------------------------------------------------------------------------------------------
*/
/**
* Render knowledge base link
*
* @param $data
*
* @since 1.0.0
*/
public function acrRenderHelpResources( $data ) {
do_action( 'acr_settings_before_help_contents', $data ); ?>