is_alp_pro_active() ) {
if ( $this->is_wc_active() ) {
$this->includes();
$this->init();
add_action( 'plugins_loaded', array( $this, 'on_plugins_loaded' ) );
add_action( 'admin_footer', array( $this, 'uninstall_notice') );
}
}
}
/**
* Callback on activation and allow to activate if pro deactivated
*
* @since 1.0.0
*/
public function on_activation() {
// Require parent plugin
if ( is_plugin_active( 'advanced-local-pickup-pro/advanced-local-pickup-pro.php' ) && current_user_can( 'activate_plugins' ) ) {
//admin notice for not allow activate plugin
wp_redirect( admin_url() . 'plugins.php?alp-not-allow=true' );
exit;
}
}
/**
* Check if ALP PRO is active
*
* @since 1.0.0
* @return bool
*/
private function is_alp_pro_active() {
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
if ( is_plugin_active( 'advanced-local-pickup-pro/advanced-local-pickup-pro.php' ) ) {
$is_active = true;
} else {
$is_active = false;
}
return $is_active;
}
/**
* Check if WooCommerce is active
*
* @since 1.0.0
* @return bool
*/
private function is_wc_active() {
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
$is_active = true;
} else {
$is_active = false;
}
// Do the WC active check
if ( false === $is_active ) {
add_action( 'admin_notices', array( $this, 'notice_activate_wc' ) );
}
return $is_active;
}
/**
* Display WC active notice
*
* @since 1.0.0
*/
public function notice_activate_wc() {
?>
get_plugin_path() . '/include/wc-local-pickup-admin.php';
$this->admin = WC_Local_Pickup_admin::get_instance();
require_once $this->get_plugin_path() . '/include/wc-local-pickup-installation.php';
$this->install = WC_Local_Pickup_install::get_instance();
// customizer
require_once $this->get_plugin_path() . '/include/customizer/wc-alp-customizer-admin.php';
$this->customizer = WC_ALP_CUSTOMIZER_ADMIN::get_instance();
}
/**
* Initialize plugin
*
* @since 1.0.0
*/
private function init() {
//callback on activate plugin
register_activation_hook( __FILE__, array( $this, 'table_create' ) );
// Load plugin textdomain
add_action('plugins_loaded', array($this, 'load_textdomain'));
//callback for migration function
add_action( 'admin_init', array( $this->install , 'wclp_update_install_callback' ) );
//load javascript in admin
add_action('admin_enqueue_scripts', array( $this, 'alp_script_enqueue' ) );
//callback for add action link for plugin page
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this , 'my_plugin_action_links' ));
add_action( 'admin_notices', array( $this, 'admin_notice_after_update' ) );
add_action('admin_init', array( $this, 'wplp_plugin_notice_ignore' ) );
add_action( 'admin_notices', array( $this, 'admin_notice_pro_update' ) );
add_action('admin_init', array( $this, 'wplp_pro_notice_ignore' ) );
add_action( 'wp_ajax_reassign_order_status', array( $this, 'reassign_order_status' ) );
// Add to custom email for WC Order statuses
add_filter( 'woocommerce_email_classes', array( $this, 'custom_init_emails' ) );
add_action( 'woocommerce_order_status_ready-pickup', array( $this, 'email_trigger_ready_pickup' ), 10, 2 );
add_action( 'woocommerce_order_status_pickup', array( $this, 'email_trigger_pickup' ), 10, 2 );
}
/**
* Database functions
*/
public function table_create() {
global $wpdb;
$this->table = $wpdb->prefix . 'alp_pickup_location';
if ($wpdb->get_var("show tables like '$this->table'") != $this->table) {
$create_table_query = "
CREATE TABLE IF NOT EXISTS `{$this->table}` (
`id` int NOT NULL AUTO_INCREMENT,
`store_name` text NULL,
`store_address` text NULL,
`store_address_2` text NULL,
`store_city` text NULL,
`store_country` text NULL,
`store_postcode` text NULL,
`store_phone` text NULL,
`store_time_format` text NULL,
`store_days` text NULL,
`store_instruction` text NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $create_table_query );
}
}
/*
* Include file on plugin load
*/
public function on_plugins_loaded() {
require_once $this->get_plugin_path() . '/include/wclp-wc-admin-notices.php';
}
/*
* load text domain
*/
public function load_textdomain() {
load_plugin_textdomain( 'advanced-local-pickup-for-woocommerce', false, plugin_dir_path( plugin_basename(__FILE__) ) . 'lang/' );
}
/**
* Gets the absolute plugin path without a trailing slash, e.g.
* /path/to/wp-content/plugins/plugin-directory.
*
* @return string plugin path
*/
public function get_plugin_path() {
if ( isset( $this->plugin_path ) ) {
return $this->plugin_path;
}
$this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
return $this->plugin_path;
}
public static function get_plugin_domain() {
return __FILE__;
}
/*
* plugin file directory function
*/
public function plugin_dir_url() {
return plugin_dir_url( __FILE__ );
}
/**
* Add plugin action links.
*
* Add a link to the settings page on the plugins.php page.
*
* @since 1.0.0
*
* @param array $links List of existing plugin action links.
* @return array List of modified plugin action links.
*/
public function my_plugin_action_links( $links ) {
$links = array_merge( array(
'' . esc_html( 'Settings', 'woocommerce' ) . ''
), array(
'' . esc_html( 'Docs', 'woocommerce' ) . ''
), array(
'' . esc_html( 'Review', 'woocommerce' ) . ''
), $links );
if (!class_exists('Advanced_local_pickup_PRO')) {
$links = array_merge( $links, array(
'' . __( 'Go Pro', 'woocommerce' ) . ''
) );
}
return $links;
}
/*
* Display admin notice on plugin install or update
*/
public function admin_notice_after_update() {
if ( get_option('wplp_review_notice_ignore') ) {
return;
}
$dismissable_url = esc_url( add_query_arg( 'wplp-review-ignore-notice', 'true' ) );
?>
'2022-04-31' ) {
return;
}
$dismissable_url = esc_url( add_query_arg( 'wplp-pro-ignore-notice', 'true' ) );
?>
Dismiss this notice.
Upgrade to Advanced Local Pickup Pro!
Automate your local pickup workflow, set up multiple pickup locations, allow customers to select pickup appointments, custom emails templates, store pickup fulfillment dashboard, and more…
Limited time offer - Use code ALPPRO20 to get 20% off on your first year license.
Upgrade Now
Dismiss
plugin_url() . '/assets/css/admin.css', array(), WC_VERSION );
wp_enqueue_style( 'woocommerce_admin_styles' );
wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip.min.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true );
wp_enqueue_script( 'jquery-tiptip' );
wp_enqueue_script( 'jquery-blockui' );
wp_enqueue_style('select2-wclp', plugins_url('assets/css/select2.min.css', __FILE__ ));
wp_enqueue_script('select2-wclp', plugins_url('assets/js/select2.min.js', __FILE__));
wp_enqueue_script( 'alp-admin-js', plugin_dir_url(__FILE__) . 'assets/js/admin.js', array(), $this->version );
wp_enqueue_style( 'alp-admin-css', plugin_dir_url(__FILE__) . 'assets/css/admin.css', array(), $this->version );
wp_localize_script( 'alp-admin-js', 'alp_object',
array(
'admin_url' => admin_url(),
)
);
}
// Add to custom email for WC Order statuses
public function custom_init_emails( $emails ) {
// Include the email class file if it's not included already
if (!defined('WC_LOCAL_PICKUP_TEMPLATE_PATH')) {
define('WC_LOCAL_PICKUP_TEMPLATE_PATH', wc_local_pickup()->get_plugin_path() . '/templates/');
}
$ready_for_pickup = get_option( 'wclp_status_ready_pickup', 0);
if (true == $ready_for_pickup) {
if ( ! isset( $emails[ 'WC_Email_Customer_Ready_Pickup_Order' ] ) ) {
$emails[ 'WC_Email_Customer_Ready_Pickup_Order' ] = include_once( 'include/emails/ready-pickup-order.php' );
}
}
$picked = get_option( 'wclp_status_picked_up', 0);
if (true == $picked) {
if ( ! isset( $emails[ 'WC_Email_Customer_Pickup_Order' ] ) ) {
$emails[ 'WC_Email_Customer_Pickup_Order' ] = include_once( 'include/emails/pickup-order.php' );
}
}
return $emails;
}
/**
* Send email when order status change to "pickuped"
*
*/
public function email_trigger_ready_pickup( $order_id, $order = false ) {
$ready_for_pickup = get_option( 'wclp_status_ready_pickup', 0);
if (true == $ready_for_pickup) {
WC()->mailer()->emails['WC_Email_Customer_Ready_Pickup_Order']->trigger( $order_id, $order );
}
}
/**
* Send email when order status change to "pickuped"
*
*/
public function email_trigger_pickup( $order_id, $order = false ) {
$picked = get_option( 'wclp_status_picked_up', 0);
if (true == $picked) {
WC()->mailer()->emails['WC_Email_Customer_Pickup_Order']->trigger( $order_id, $order );
}
}
/*
* Plugin uninstall code
*/
public function uninstall_notice() {
$screen = get_current_screen();
if ('plugins.php' != $screen->parent_file) {
return;
}
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'alp-admin-js', plugin_dir_url(__FILE__) . 'assets/css/admin.css', array(), $this->version );
wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true );
wp_enqueue_script( 'jquery-blockui' );
$ready_pickup_count = wc_orders_count( 'ready-pickup' );
$pickup_count = wc_orders_count( 'pickup' );
$order_statuses = wc_get_order_statuses();
unset($order_statuses['wc-ready-pickup']);
unset($order_statuses['wc-pickup']);
if ($ready_pickup_count > 0 || $pickup_count > 0) {
?>
'ready-pickup',
'limit' => '-1',
);
$orders = wc_get_orders( $args );
foreach ($orders as $order) {
$order_id = $order->get_id();
$order = new WC_Order($order_id);
$order->update_status($reassign_ready_pickup_order);
}
}
if ('' != $reassign_pickedup_order) {
$args = array(
'status' => 'pickup',
'limit' => '-1',
);
$ps_orders = wc_get_orders( $args );
foreach ($ps_orders as $order) {
$order_id = $order->get_id();
$order = new WC_Order($order_id);
$order->update_status($reassign_pickedup_order);
}
}
exit;
echo 1;
die();
}
}
/**
* Returns an instance of Woocommerce_local_pickup.
*
* @since 1.6.5
* @version 1.6.5
*
* @return Woocommerce_local_pickup
*/
function wc_local_pickup() {
static $instance;
if ( ! isset( $instance ) ) {
$instance = new Woocommerce_local_pickup();
}
return $instance;
}
/**
* Register this class globally.
*
* Backward compatibility.
*/
wc_local_pickup();
add_action( 'before_woocommerce_init', function() {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
} );