Plugin Directory

Changeset 3018587


Ignore:
Timestamp:
01/08/2024 07:29:46 AM (2 years ago)
Author:
moceanapiplugin
Message:

Added option to send to shipping recipient

Location:
moceansms-order-sms-notification-for-woocommerce
Files:
482 added
5 edited

Legend:

Unmodified
Added
Removed
  • moceansms-order-sms-notification-for-woocommerce/trunk/admin/class-moceansms-woocommerce-setting.php

    r3009374 r3018587  
    1818        // if ( class_exists( 'woocommerce' ) ) {
    1919            add_action( 'admin_init', array( $this, 'admin_init' ) );
     20            add_action( 'admin_init', array( $this, 'initialise_default_recipient_setting' ) );
    2021            add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    2122            add_action( 'moceansms_setting_fields_custom_html', array( $this, 'moceansms_wc_not_activated' ), 10, 1 );
     
    211212                    'type'    => 'checkbox',
    212213                    'default' => 'off'
     214                ),
     215                array(
     216                    'name'    => 'moceansms_woocommerce_send_sms_to',
     217                    'label'   => __( 'Send SMS to', MOCEANSMS_TEXT_DOMAIN ),
     218                    'desc'    => ' ' . __( 'Choose who to send SMS to', MOCEANSMS_TEXT_DOMAIN ),
     219                    'type'    => 'multicheck',
     220                    'default' => array(
     221                        'billing-recipient'  => 'billing-recipient',
     222                    ),
     223                    'options' => array(
     224                        'billing-recipient'  => 'Billing Recipient',
     225                        'shipping-recipient' => 'Shipping Recipient',
     226                    )
    213227                ),
    214228                array(
     
    410424        return $pages_options;
    411425    }
     426
     427    public function initialise_default_recipient_setting() {
     428
     429        if( !get_option("moceansms_customer_setting") ) {
     430            // this is because new users.
     431            // no settings to anything.
     432            return;
     433        }
     434
     435        $default_setting = [
     436            'billing-recipient' => 'billing-recipient'
     437        ];
     438
     439        $option_setting = moceansms_get_options("moceansms_woocommerce_send_sms_to", "moceansms_customer_setting");
     440
     441        // no settings, usually after update plugin.
     442        if(empty($option_setting)) {
     443            return moceansms_update_options("moceansms_woocommerce_send_sms_to", $default_setting, "moceansms_customer_setting");
     444        }
     445
     446        $send_to_billing_recipient = "";
     447        $send_to_shipping_recipient = "";
     448
     449        if( isset($option_setting['billing-recipient']) ) {
     450            $send_to_billing_recipient = $option_setting['billing-recipient'];
     451        }
     452
     453        if( isset($option_setting['shipping-recipient']) ) {
     454            $send_to_shipping_recipient = $option_setting['shipping-recipient'];
     455        }
     456
     457        // var_dump($option_setting);
     458        // var_dump($send_to_billing_recipient);
     459        // var_dump($send_to_shipping_recipient);
     460        if( empty($send_to_billing_recipient) && empty($send_to_shipping_recipient) ) {
     461            return moceansms_update_options("moceansms_woocommerce_send_sms_to", $default_setting, "moceansms_customer_setting");
     462        }
     463    }
    412464
    413465    public function check_domain_reachability()
  • moceansms-order-sms-notification-for-woocommerce/trunk/includes/class-moceansms-helper.php

    r2749078 r3018587  
    2626}
    2727
     28if ( ! function_exists( 'moceansms_update_options' ) ) {
     29    /**
     30     * @param $option
     31     * @param $section
     32     * @param array|string $default
     33     *
     34     * @return mixed
     35     */
     36    function moceansms_update_options( $option, $value, $section ) {
     37        $options = get_option( $section, [] );
     38        $options[ $option ] = $value;
     39        return update_option($section, $options);
     40    }
     41}
     42
    2843if ( ! function_exists( 'moceansms_add_actions' ) ) {
    2944    /**
  • moceansms-order-sms-notification-for-woocommerce/trunk/includes/class-moceansms-woocommerce-notification.php

    r2749078 r3018587  
    147147                return;
    148148            }
     149
     150            $sms_recipient_setting = moceansms_get_options("moceansms_woocommerce_send_sms_to", "moceansms_customer_setting");
     151
    149152            $message           = $this->replace_order_keyword( $message, $order_details, 'customer', $status );
    150             $customer_phone_no = $this->check_and_get_phone_number( $order_details->get_billing_phone(), $order_details->get_billing_country() );
    151 
    152             if ( $customer_phone_no !== false ) {
    153                 $this->log->add( 'MoceanSMS', 'Customer\'s billing phone number (' . $order_details->get_billing_phone() . ') in country (' . $order_details->get_billing_country() . ') converted to ' . $customer_phone_no );
    154             } else {
    155                 $customer_phone_no = $order_details->get_billing_phone();
    156             }
    157             MoceanSMS_SendSMS_Sms::send_sms( '', $customer_phone_no, $message );
     153
     154            if( isset($sms_recipient_setting['billing-recipient']) ) {
     155                $customer_billing_phone = $this->check_and_get_phone_number( $order_details->get_billing_phone(), $order_details->get_billing_country() );
     156                if ( $customer_billing_phone !== false ) {
     157                    $this->log->add( 'MoceanSMS', 'Customer\'s billing phone number (' . $order_details->get_billing_phone() . ') in country (' . $order_details->get_billing_country() . ') converted to ' . $customer_billing_phone );
     158                } else {
     159                    $customer_billing_phone = $order_details->get_billing_phone();
     160                }
     161                MoceanSMS_SendSMS_Sms::send_sms( '', $customer_billing_phone, $message );
     162            }
     163
     164            if ( isset($sms_recipient_setting['shipping-recipient']) ) {
     165                $customer_shipping_phone = $this->check_and_get_phone_number( $order_details->get_shipping_phone(), $order_details->get_shipping_country() );
     166
     167                if ( $customer_shipping_phone !== false ) {
     168                    $this->log->add( 'MoceanSMS', 'Customer\'s shipping phone number (' . $order_details->get_shipping_phone() . ') in country (' . $order_details->get_shipping_country() . ') converted to ' . $customer_shipping_phone );
     169                } else {
     170                    $customer_shipping_phone = $order_details->get_shipping_phone();
     171                }
     172                MoceanSMS_SendSMS_Sms::send_sms( '', $customer_shipping_phone, $message );
     173            }
     174
    158175        }
    159176    }
  • moceansms-order-sms-notification-for-woocommerce/trunk/moceansms-woocommerce.php

    r3009374 r3018587  
    55Plugin URI:  https://dashboard.moceanapi.com
    66Description: MoceanAPI Order SMS Notification for WooCommerce
    7 Version:     1.4.10
     7Version:     1.4.11
    88Author:      Micro Ocean Technologies
    99Author URI:  https://moceanapi.com
  • moceansms-order-sms-notification-for-woocommerce/trunk/readme.txt

    r3009374 r3018587  
    66WC requires at least: 2.6
    77WC tested up to: 5.2.2
    8 Stable tag: 1.4.10
     8Stable tag: 1.4.11
    99Requires PHP: 5.6
    1010License: GPLv3
     
    109109
    110110== Changelog ==
     111
     112= 1.4.11 =
     113* Added option to send to Shipping recipient
    111114
    112115= 1.4.10 =
Note: See TracChangeset for help on using the changeset viewer.