includes(); if ( 'yes' == get_option( 'ywsn_enable_plugin' ) ) { add_action( 'init', array( $this, 'init_multivendor_integration' ), 20 ); if ( 'none' == get_option( 'ywsn_sms_gateway' ) ) { add_action( 'admin_notices', array( $this, 'add_admin_notices' ) ); } if ( 'requested' == get_option( 'ywsn_customer_notification' ) ) { add_action( 'woocommerce_after_checkout_billing_form', array( $this, 'show_sms_request_option' ) ); add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'save_sms_request_option' ) ); } foreach ( array_keys( wc_get_order_statuses() ) as $status ) { $slug = ( 'wc-' === substr( $status, 0, 3 ) ) ? substr( $status, 3 ) : $status; add_action( 'woocommerce_order_status_' . $slug, array( $this, 'order_status_changed' ), 99, 2 ); } } } /** * Files inclusion * * @since 1.0.0 * @return void * @author Alberto Ruggiero */ private function includes() { include_once( 'includes/class-ywsn-messages.php' ); include_once( 'includes/class-ywsn-sms-gateway.php' ); include_once( 'includes/class-ywsn-url-shortener.php' ); if ( is_admin() ) { include_once( 'includes/class-ywsn-ajax.php' ); include_once( 'includes/class-ywsn-metabox.php' ); include_once( 'templates/admin/class-yith-wc-custom-checklist.php' ); include_once( 'templates/admin/class-yith-wc-custom-textarea.php' ); include_once( 'templates/admin/class-yith-wc-custom-label.php' ); include_once( 'templates/admin/class-yith-wc-check-matrix-table.php' ); include_once( 'templates/admin/class-ywsn-sms-send.php' ); } } /** * Add a panel under YITH Plugins tab * * @since 1.0.0 * @return void * @author Alberto Ruggiero * @use /Yit_Plugin_Panel class * @see plugin-fw/lib/yit-plugin-panel.php */ public function add_menu_page() { if ( ! empty( $this->_panel ) ) { return; } $admin_tabs = array( 'general' => _x( 'General Settings', 'general settings tab name', 'yith-woocommerce-sms-notifications' ), 'messages' => _x( 'SMS Settings', 'sms settings tab name', 'yith-woocommerce-sms-notifications' ), 'howto' => _x( 'How-to', 'how-to tab name', 'yith-woocommerce-sms-notifications' ), ); $args = array( 'create_menu_page' => true, 'parent_slug' => '', 'page_title' => _x( 'SMS Notifications', 'plugin name in admin page title', 'yith-woocommerce-sms-notifications' ), 'menu_title' => _x( 'SMS Notifications', 'plugin name in admin WP menu', 'yith-woocommerce-sms-notifications' ), 'capability' => 'manage_options', 'parent' => '', 'parent_page' => 'yit_plugin_panel', 'page' => $this->_panel_page, 'admin-tabs' => $admin_tabs, 'options-path' => YWSN_DIR . 'plugin-options' ); $this->_panel = new YIT_Plugin_Panel_WooCommerce( $args ); } /** * Add scipts and styles * * @since 1.0.0 * @return void * @author Alberto Ruggiero */ public function admin_scripts() { global $post; $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style( 'ywsn-admin', YWSN_ASSETS_URL . '/css/ywsn-admin' . $suffix . '.css' ); wp_enqueue_script( 'ywsn-admin', YWSN_ASSETS_URL . '/js/ywsn-admin' . $suffix . '.js', array( 'jquery' ) ); $ext_charset = apply_filters( 'ywsn_additional_charsets', array() ); $sms_length = empty( $ext_charset ) ? 160 : 70; $params = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'order_id' => isset( $post->ID ) ? $post->ID : '', 'sms_length' => apply_filters( 'ywsn_sms_limit', $sms_length ), 'sms_customer_notification' => get_option( 'ywsn_customer_notification' ), 'sms_after_send' => __( 'Message sent successfully!', 'yith-woocommerce-sms-notifications' ), 'sms_no_message' => __( 'Please select the type of message you want to send.', 'yith-woocommerce-sms-notifications' ), 'sms_empty_message' => __( 'Your message is blank!', 'yith-woocommerce-sms-notifications' ), 'sms_wrong' => __( 'Please enter a valid phone number.', 'yith-woocommerce-sms-notifications' ), 'sms_before_send' => __( 'Sending...', 'yith-woocommerce-sms-notifications' ), 'sms_manual_send_advice' => __( 'The client did not requested sms notifications. Do you really want to send it?', 'yith-woocommerce-sms-notifications' ), ); wp_localize_script( 'ywsn-admin', 'ywsn_admin', $params ); } /** * Advise if the plugin cannot be performed * * @since 1.0.0 * @return void * @author Alberto Ruggiero */ public function add_admin_notices() { ?>

get_active_sms( $order ); if ( isset( $active_sms[ $order_status ]['customer'] ) && 1 == $active_sms[ $order_status ]['customer'] && $this->user_receives_sms( $order_id ) && wp_get_post_parent_id( $order_id ) == 0 ) { if ( '' != yit_get_prop( $order, '_billing_phone' ) ) { $customer_sms = new YWSN_Messages( $order, true ); $customer_sms->single_sms(); } } if ( isset( $active_sms[ $order_status ]['admin'] ) && 1 == $active_sms[ $order_status ]['admin'] ) { $admin_sms = new YWSN_Messages( $order, false ); $admin_sms->admins_sms(); } } /** * Get active SMS list with special behavior for sub-orders * * @since 1.0.3 * * @param $order * * @return array * @author Alberto Ruggiero */ public function get_active_sms( WC_Order $order ) { $active_sms = array(); if ( wp_get_post_parent_id( yit_get_order_id( $order ) ) != 0 ) { $active_sms = apply_filters( 'ywsn_active_sms', array(), $order ); } else { $active_sms = get_option( 'ywsn_sms_active_send' ); } return $active_sms; } /** * Check if customer wants to receive SMS * * @since 1.0.0 * * @param $order_id * * @return bool * @author Alberto Ruggiero */ public function user_receives_sms( $order_id ) { if ( 'requested' == get_option( 'ywsn_customer_notification' ) ) { $order = wc_get_order( $order_id ); $receive_sms = yit_get_prop( $order, '_ywsn_receive_sms' ); return ( $receive_sms == 'yes' ); } else { return true; } } /** * Show SMS request checkbox in checkout page * * @since 1.0.0 * @return void * @author Alberto Ruggiero */ public function show_sms_request_option() { if ( ! empty( $_POST['ywsn_receive_sms'] ) ) { $value = wc_clean( $_POST['ywsn_receive_sms'] ); } else { $value = get_option( 'ywsn_checkout_checkbox_value' ) == 'yes'; } $label = apply_filters( 'ywsn_checkout_option_label', get_option( 'ywsn_checkout_checkbox_text' ) ); if ( ! empty( $label ) ) { woocommerce_form_field( 'ywsn_receive_sms', array( 'type' => 'checkbox', 'class' => array( 'form-row-wide' ), 'label' => $label, ), $value ); } } /** * Save SMS request checkbox in checkout page * * @since 1.0.0 * * @param $order_id * * @return void * @author Alberto Ruggiero */ public function save_sms_request_option( $order_id ) { if ( ! empty( $_POST['ywsn_receive_sms'] ) ) { $order = wc_get_order( $order_id ); $receive_sms = isset( $_POST['ywsn_receive_sms'] ) ? 'yes' : 'no'; yit_save_prop( $order, '_ywsn_receive_sms', $receive_sms, true ); } } /** * Enable unsafe URLs for some SMS operator * * @since 1.0.8 * * @param $args * * @return array * @author Alberto Ruggiero */ public function enable_unsafe_urls( $args ) { $active_gateway = get_option( 'ywsn_sms_gateway' ); $enabled_gateways = array( 'YWSN_Jazz' ); if ( in_array( $active_gateway, $enabled_gateways ) ) { $args['reject_unsafe_urls'] = false; } return $args; } /** * Add YITH WooCommerce Multi Vendor integration * * @since 1.0.3 * @return void * @author Alberto Ruggiero */ public function init_multivendor_integration() { if ( $this->is_multivendor_active() ) { include_once( 'includes/class-ywsn-multivendor.php' ); } } /** * Check if YITH WooCommerce Multi Vendor is active * * @since 1.0.3 * @return bool * @author Alberto Ruggiero */ public function is_multivendor_active() { return defined( 'YITH_WPV_PREMIUM' ) && YITH_WPV_PREMIUM; } /** * Get Placeholders reference * * @since 1.0.8 * @return array * @author Alberto Ruggiero */ public function placeholder_reference() { $placeholders = array( '{site_title}' => __( 'Website name', 'yith-woocommerce-sms-notifications' ), '{order_id}' => __( 'Order number', 'yith-woocommerce-sms-notifications' ), '{order_total}' => __( 'Order total', 'yith-woocommerce-sms-notifications' ), '{order_status}' => __( 'Order status', 'yith-woocommerce-sms-notifications' ), '{billing_name}' => __( 'Billing name', 'yith-woocommerce-sms-notifications' ), '{shipping_name}' => __( 'Shipping name', 'yith-woocommerce-sms-notifications' ), '{shipping_method}' => __( 'Shipping method', 'yith-woocommerce-sms-notifications' ), '{additional_notes}' => __( 'Additional Notes', 'yith-woocommerce-sms-notifications' ), '{order_date}' => __( 'Order Date', 'yith-woocommerce-sms-notifications' ), '{order_product}' => __('Order Product', 'yith-woocommerce-sms-notifications' ), ); if ( function_exists( 'YITH_YWOT' ) ) { $placeholders['{tracking_number}'] = __( 'Tracking Number', 'yith-woocommerce-sms-notifications' ); $placeholders['{carrier_name}'] = __( 'Carrier name', 'yith-woocommerce-sms-notifications' ); $placeholders['{shipping_date}'] = __( 'Shipping date', 'yith-woocommerce-sms-notifications' ); } return $placeholders; } /** * YITH FRAMEWORK */ /** * Load plugin framework * * @since 1.0.0 * @return void * @author Andrea Grillo * */ public function plugin_fw_loader() { if ( ! defined( 'YIT_CORE_PLUGIN' ) ) { global $plugin_fw_data; if ( ! empty( $plugin_fw_data ) ) { $plugin_fw_file = array_shift( $plugin_fw_data ); require_once( $plugin_fw_file ); } } } /** * Get the premium landing uri * * @since 1.0.0 * @return string The premium landing link * @author Andrea Grillo */ public function get_premium_landing_uri() { return defined( 'YITH_REFER_ID' ) ? $this->_premium_landing . '?refer_id=' . YITH_REFER_ID : $this->_premium_landing; } /** * Action Links * * add the action links to plugin admin page * @since 1.0.0 * * @param $links | links plugin array * * @return mixed * @author Andrea Grillo * @use plugin_action_links_{$plugin_file_name} */ public function action_links( $links ) { $links[] = '_panel_page}" ) . '">' . __( 'Settings', 'yith-woocommerce-sms-notifications' ) . ''; return $links; } /** * Plugin row meta * * add the action links to plugin admin page * * @since 1.0.0 * * @param $plugin_meta * @param $plugin_file * @param $plugin_data * @param $status * * @return array * @author Andrea Grillo * @use plugin_row_meta */ public function plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) { if ( ( defined( 'YWSN_INIT' ) && ( YWSN_INIT == $plugin_file ) ) ) { $plugin_meta[] = '' . __( 'Plugin documentation', 'yith-woocommerce-sms-notifications' ) . ''; } return $plugin_meta; } /** * Register plugins for activation tab * * @since 2.0.0 * @return void * @author Andrea Grillo */ public function register_plugin_for_activation() { /*if ( ! class_exists( 'YIT_Plugin_Licence' ) ) { require_once 'plugin-fw/licence/lib/yit-licence.php'; require_once 'plugin-fw/licence/lib/yit-plugin-licence.php'; }*/ YIT_Plugin_Licence()->register( YWSN_INIT, YWSN_SECRET_KEY, YWSN_SLUG ); } /** * Register plugins for update tab * * @since 2.0.0 * @return void * @author Andrea Grillo */ public function register_plugin_for_updates() { /*if ( ! class_exists( 'YIT_Upgrade' ) ) { require_once( 'plugin-fw/lib/yit-upgrade.php' ); }*/ YIT_Upgrade()->register( YWSN_SLUG, YWSN_INIT ); } } }