Plugin Directory

Changeset 3018586


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

Added option to send to shipping recipient

Location:
moceanapi-sendsms
Files:
482 added
5 edited

Legend:

Unmodified
Added
Removed
  • moceanapi-sendsms/trunk/admin/class-moceansms-woocommerce-setting.php

    r3009373 r3018586  
    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' ) );
     21
    2022            add_action( 'admin_menu', array( $this, 'admin_menu' ) );
    2123            add_action( 'moceansms_setting_fields_custom_html', array( $this, 'moceansms_wc_not_activated' ), 10, 1 );
     
    207209                    'type'    => 'checkbox',
    208210                    'default' => 'off'
     211                ),
     212                array(
     213                    'name'    => 'moceansms_woocommerce_send_sms_to',
     214                    'label'   => __( 'Send SMS to', MOCEANSMS_TEXT_DOMAIN ),
     215                    'desc'    => ' ' . __( 'Choose who to send SMS to', MOCEANSMS_TEXT_DOMAIN ),
     216                    'type'    => 'multicheck',
     217                    'default' => array(
     218                        'billing-recipient'  => 'billing-recipient',
     219                    ),
     220                    'options' => array(
     221                        'billing-recipient'  => 'Billing Recipient',
     222                        'shipping-recipient' => 'Shipping Recipient',
     223                    )
    209224                ),
    210225                array(
     
    406421        return $pages_options;
    407422    }
     423
     424    public function initialise_default_recipient_setting() {
     425
     426        if( !get_option("moceansms_customer_setting") ) {
     427            // this is because new users.
     428            // no settings to anything.
     429            return;
     430        }
     431
     432        $default_setting = [
     433            'billing-recipient' => 'billing-recipient'
     434        ];
     435
     436        $option_setting = moceansms_get_options("moceansms_woocommerce_send_sms_to", "moceansms_customer_setting");
     437
     438        // no settings, usually after update plugin.
     439        if(empty($option_setting)) {
     440            return moceansms_update_options("moceansms_woocommerce_send_sms_to", $default_setting, "moceansms_customer_setting");
     441        }
     442
     443        $send_to_billing_recipient = "";
     444        $send_to_shipping_recipient = "";
     445
     446        if( isset($option_setting['billing-recipient']) ) {
     447            $send_to_billing_recipient = $option_setting['billing-recipient'];
     448        }
     449
     450        if( isset($option_setting['shipping-recipient']) ) {
     451            $send_to_shipping_recipient = $option_setting['shipping-recipient'];
     452        }
     453
     454        // var_dump($option_setting);
     455        // var_dump($send_to_billing_recipient);
     456        // var_dump($send_to_shipping_recipient);
     457        if( empty($send_to_billing_recipient) && empty($send_to_shipping_recipient) ) {
     458            return moceansms_update_options("moceansms_woocommerce_send_sms_to", $default_setting, "moceansms_customer_setting");
     459        }
     460    }
    408461
    409462    public function check_domain_reachability()
  • moceanapi-sendsms/trunk/includes/class-moceansms-helper.php

    r2749034 r3018586  
    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    /**
  • moceanapi-sendsms/trunk/includes/class-moceansms-woocommerce-notification.php

    r2872937 r3018586  
    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    }
  • moceanapi-sendsms/trunk/moceansms-woocommerce.php

    r3009373 r3018586  
    55Plugin URI:  https://dashboard.moceanapi.com
    66Description: MoceanAPI Send SMS
    7 Version:     1.4.9
     7Version:     1.4.10
    88Author:      Micro Ocean Technologies
    99Author URI:  https://moceanapi.com
  • moceanapi-sendsms/trunk/readme.txt

    r3009373 r3018586  
    44Requires at least: 3.8
    55Tested up to: 6.0
    6 Stable tag: 1.4.9
     6Stable tag: 1.4.10
    77
    88A plugin to send SMS notification to your wordpress users
     
    155155
    156156== Changelog ==
     157
     158= 1.4.10 =
     159* Added option to send to shipping recipient
    157160
    158161= 1.4.9 =
Note: See TracChangeset for help on using the changeset viewer.