Does the customer want to receive 360Messenger messages: '. ( WooNotify()->maybeBool( $want_360Messenger ) ? 'Yes' : 'No' ) . '
';
}
echo '
';
if ( WooNotify()->maybeBool( get_post_meta( $order->get_id(), '_allow_buyer_select_status', true ) ) ) {
$buyer_360Messenger_status = (array) get_post_meta( $order->get_id(), '_buyer_360Messenger_status', true );
$buyer_360Messenger_status = array_filter( $buyer_360Messenger_status );
if (get_locale() == 'fa_IR')
echo 'وضعیت های انتخابی توسط مشتری برای دریافت پیام واتساپ : ';
else
echo 'situations selected by the customer to receive 360Messenger messages: ';
if ( ! empty( $buyer_360Messenger_status ) ) {
$statuses = [];
foreach ( $buyer_360Messenger_status as $status ) {
$statuses[] = WooNotify()->statusName( $status );
}
echo esc_html( implode( ' - ', $statuses ) );
} else {
if (get_locale() == 'fa_IR')
echo 'وضعیتی انتخاب نشده است.';
else
echo 'A status is not selected.';
}
} else {
if (get_locale() == 'fa_IR')
echo 'مشتری حق انتخاب وضعیت های دریافت پیام واتساپ را ندارد و از تنظیمات افزونه پیروی میکند.';
else
echo 'The customer does not have the right to choose the status of receiving 360Messenger messages and follows the settings of the plugin.';
/*
$allowed_status = WooNotify()->GetBuyerAllowedStatuses();
if ( ! empty( $allowed_status ) ) {
echo ' وضعیت مجاز برای دریافت پیامک با توجه به تنظیمات: ' . ' ';
echo esc_html( implode( ' - ', array_values( $allowed_status ) ) );
}
*/
}
echo '
';
}
public function sendOrder360Messenger( int $order_id, $old_status = '', $new_status = 'created' ) {
if ( current_action() == 'woocommerce_process_shop_order_meta' ) {
if ( ! is_admin() ) {
return;
}
} else {
remove_action( 'woocommerce_process_shop_order_meta', [ $this, 'sendOrder360Messenger' ], 999 );
}
$new_status = WooNotify()->modifyStatus( $new_status );
if ( ! $order_id ) {
return;
}
$order = new WC_Order( $order_id );
// Customer
$order_page = ( $_POST['is_shop_order'] ?? null ) == 'true';
if ( ( $order_page && ! empty( $_POST['360Messenger_order_send'] ) ) || ( ! $order_page && $this->buyerCanGet360Messenger( $order_id, $new_status ) ) ) {
$mobile = WooNotify()->buyerMobile( $order_id );
$message = isset( $_POST['360Messenger_order_text'] ) ? sanitize_textarea_field( $_POST['360Messenger_order_text'] ) : WooNotify()->Options( '360Messenger_body_' . $new_status );
$data = [
'post_id' => $order_id,
'type' => 2,
'mobile' => $mobile,
'message' => WooNotify()->ReplaceShortCodes( $message, $new_status, $order ),
];
if ( ( $result = WooNotify()->Send360Messenger( $data ) ) === true ) {
if (get_locale() == 'fa_IR')
$order->add_order_note( sprintf( 'پیام با موفقیت به مشتری با شماره واتساپ %s ارسال گردید.', $mobile ) );
else
$order->add_order_note( sprintf( 'The message was successfully sent to the customer with the 360Messenger number %s.', $mobile ) );
} else {
if (get_locale() == 'fa_IR')
$order->add_order_note( sprintf( 'پیام بخاطر خطا به مشتری با شماره واتساپ %s ارسال نشد. پاسخ وبسرویس: %s', $mobile, $result ) );
else
$order->add_order_note( sprintf( 'The message could not be sent to the customer with 360Messenger number %s due to an error. Web service response: %s', $mobile, $result ) );
}
}
//superAdmin
if ( $this->enable_super_admin_360Messenger && in_array( $new_status, (array) WooNotify()->Options( 'super_admin_order_status' ) ) ) {
$mobile = WooNotify()->Options( 'super_admin_phone' );
$message = WooNotify()->Options( 'super_admin_360Messenger_body_' . $new_status );
$data = [
'post_id' => $order_id,
'type' => 4,
'mobile' => $mobile,
'message' => WooNotify()->ReplaceShortCodes( $message, $new_status, $order ),
];
if ( ( $result = WooNotify()->Send360Messenger( $data ) ) === true ) {
if (get_locale() == 'fa_IR')
$order->add_order_note( sprintf( 'پیام با موفقیت به مدیر کل با شماره واتساپ %s ارسال گردید.', $mobile ) );
else
$order->add_order_note( sprintf( 'The message was successfully sent to the general manager with the 360Messenger number %s.', $mobile ) );
} else {
$order->add_order_note( sprintf( 'پیامک بخاطر خطا به مدیر کل با شماره %s ارسال نشد. پاسخ وبسرویس: %s', $mobile, $result ) );
}
}
//productAdmin
if ( $this->enable_product_admin_360Messenger ) {
$order_products = WooNotify()->GetProdcutLists( $order, 'product_id' );
$mobiles = WooNotify()->ProductAdminMobiles( $order_products['product_id'], $new_status );
foreach ( (array) $mobiles as $mobile => $product_ids ) {
$vendor_items = WooNotify()->ProductAdminItems( $order_products, $product_ids );
$message = WooNotify()->Options( 'product_admin_360Messenger_body_' . $new_status );
$data = [
'post_id' => $order_id,
'type' => 5,
'mobile' => $mobile,
'message' => WooNotify()->ReplaceShortCodes( $message, $new_status, $order, $vendor_items ),
];
if ( ( $result = WooNotify()->Send360Messenger( $data ) ) === true ) {
if (get_locale() == 'fa_IR')
$order->add_order_note( sprintf( 'پیام با موفقیت به مدیر محصول با شماره واتساپ %s ارسال گردید.', $mobile ) );
else
$order->add_order_note( sprintf( 'The message was successfully sent to the product manager with the 360Messenger number %s.', $mobile ) );
} else {
if (get_locale() == 'fa_IR')
$order->add_order_note( sprintf( 'پیام بخاطر خطا به مدیر محصول با شماره واتساپ %s ارسال نشد. پاسخ وبسرویس: %s', $mobile, $result ) );
else
$order->add_order_note( sprintf( 'The message could not be sent to the product manager with the 360Messenger number %s due to an error. Response from the web service: %s', $mobile, $result ) );
}
}
}
}
public function buyerCanGet360Messenger( int $order_id, string $new_status ): bool {
if ( ! $this->enabled_buyers ) {
return false;
}
if ( ! $order_id ) {
return false;
}
$order = new WC_Order( $order_id );
$allowed_status = array_keys( WooNotify()->GetBuyerAllowedStatuses() );
if ( is_admin() ) {
$status = WooNotify()->OrderProp( $order, 'status' );
$created_via = WooNotify()->OrderProp( $order, 'created_via' );
if ( $created_via == 'admin' || ! in_array( $status, array_keys( WooNotify()->GetAllStatuses() ) ) ) {
update_post_meta( $order_id, '_force_enable_buyer', WooNotify()->Options( 'force_enable_buyer', '__' ) );
update_post_meta( $order_id, '_allow_buyer_select_status', WooNotify()->Options( 'allow_buyer_select_status', '__' ) );
update_post_meta( $order_id, '_buyer_360Messenger_notify', 'yes' );
update_post_meta( $order_id, '_buyer_360Messenger_status', $allowed_status );
}
}
if ( ! WooNotify()->validateMobile( WooNotify()->buyerMobile( $order_id ) ) ) {
return false;
}
if ( in_array( $new_status, $allowed_status ) && WooNotify()->maybeBool( get_post_meta( $order_id, '_buyer_360Messenger_notify', true ) ) ) {
$buyer_360Messenger_status = (array) get_post_meta( $order_id, '_buyer_360Messenger_status', true );
$allow_select_status = WooNotify()->maybeBool( get_post_meta( $order_id, '_allow_buyer_select_status', true ) );
if ( ! $allow_select_status || ( $allow_select_status && in_array( $new_status, $buyer_360Messenger_status ) ) ) {
return true;
}
}
return false;
}
public function change360MessengerTextJS( WC_Order $order ) {
if ( $this->enabled_buyers && WooNotify()->validateMobile( WooNotify()->buyerMobile( $order->get_id() ) ) ) { ?>
modifyStatus( $_order_status );
}
$order = new WC_Order( $order_id );
$message = WooNotify()->Options( '360Messenger_body_' . $new_status );
$message = WooNotify()->ReplaceShortCodes( $message, $new_status, $order );
echo '';
echo '';
if ( $this->buyerCanGet360Messenger( $order_id, $new_status ) ) {
$woonotify_360messenger_checked = 'checked="checked"';
if (get_locale() == 'fa_IR')
$description = 'با توجه به تنظیمات و انتخاب ها، مشتری باید این پیام را دریافت کند. ولی میتوانید ارسال پیام واتساپ به او را از طریق این چک باکس غیرفعال نمایید.';
else
$description = 'According to the settings and choices, the client should receive this message. But you can disable sending 360Messenger messages to him through this check box.';
} else {
$woonotify_360messenger_checked = '';
if (get_locale() == 'fa_IR')
$description = 'با توجه به تنظیمات و انتخاب ها، مشتری نباید این پیام را دریافت کند. ولی میتوانید ارسال پیام واتساپ به او را از طریق این چک باکس فعال نمایید.';
else
$description = 'Due to settings and choices, the client should not receive this message. But you can send 360Messenger messages to him through this check box.';
}
echo '
' . esc_attr( $description ) . '';
die();
}
}
new WooNotify_360Messenger_Orders();