maybeBool( $option ); } return $option; } public function modifyStatus( $status ) { return str_ireplace( array( 'wc-', 'wc_' ), '', $status ); } public function get_variation( $order_id ) { // Get an instance of the WC_Order object from an Order ID $order = wc_get_order( $order_id ); // Loop though order "line items" foreach( $order->get_items() as $item_id => $item ){ $product_id = $item->get_product_id(); //Get the product ID $quantity = $item->get_quantity(); //Get the product QTY $product_name = $item->get_name(); //Get the product NAME // Get an instance of the WC_Product object (can be a product variation too) $product = $item->get_product(); // Get the product description (works for product variation too) $description = $product->get_description(); // Only for product variation if( $product->is_type('variation') ){ // Get the variation attributes $variation_attributes = $product->get_variation_attributes(); // Loop through each selected attributes foreach($variation_attributes as $attribute_taxonomy => $term_slug ){ // Get product attribute name or taxonomy $taxonomy = str_replace('attribute_', '', $attribute_taxonomy ); // The label name from the product attribute $attribute_name = wc_attribute_label( $taxonomy, $product ); // The term name (or value) from this attribute if( taxonomy_exists($taxonomy) ) { $attribute_value = get_term_by( 'slug', $term_slug, $taxonomy )->name; } else { $attribute_value = $term_slug; // For custom product attributes } } } } return $attribute_name.'-'.$attribute_value; } public function statusName( $status, $pending = false ) { $status = wc_get_order_status_name( $status ); $pending_label = _x( 'Pending payment', 'Order status', 'woocommerce' ); if (get_locale() == 'fa_IR') $status = $pending ? $pending_label : $pending_label . ' (بلافاصله بعد از ثبت سفارش)'; else $status = $pending ? $pending_label:$pending_label. ' (immediately after placing the order)'; return $status; } public function GetAllStatuses( $pending = false ) { if ( ! function_exists( 'wc_get_order_statuses' ) ) { return array(); } $statuses = wc_get_order_statuses(); $pending_label = _x( 'Pending payment', 'Order status', 'woocommerce' ); if ( ! empty( $statuses['wc-pending'] ) ) { if (get_locale() == 'fa_IR') $statuses['wc-pending'] = $pending ? $pending_label : $pending_label . ' (بعد از تغییر وضعیت سفارش)'; else $status['wc-pending'] = $pending ? $pending_label: $pending_label. ' (after changing the status of the order)'; } if ( empty( $statuses['wc-created'] ) ) { if (get_locale() == 'fa_IR') $statuses = array_merge( array( 'wc-created' => $pending ? 'بعد از ثبت سفارش' : $pending_label . ' (بلافاصله بعد از ثبت سفارش)' ), $statuses ); else $statuses = array_merge( array( 'wc-created' => $pending ? 'After placing the order' : $pending_label . ' (Immediately after placing the order)' ), $statuses ); } $opt_statuses = array(); foreach ( (array) $statuses as $status_val => $status_name ) { $opt_statuses[ $this->modifyStatus( $status_val ) ] = $status_name; } return $opt_statuses; } public function GetAllSuperAdminStatuses( $pending = false ) { $opt_statuses = $this->GetAllStatuses( $pending ); if (get_locale() == 'fa_IR'){ $opt_statuses['low'] = 'کم بودن موجودی انبار'; $opt_statuses['out'] = 'تمام شدن موجودی انبار'; } else { $opt_statuses['low'] = 'low inventory'; $opt_statuses['out'] = 'Out of stock'; } return $opt_statuses; } public function GetAllProductAdminStatuses( $pending = false ) { $opt_statuses = $this->GetAllSuperAdminStatuses( $pending ); return $opt_statuses; } public function prepareAdminProductStatus( $statuses, $array = true ) { $delimator = '-sv-'; if ( ! is_array( $statuses ) ) { $statuses = explode( $delimator, $statuses ); } $statuses = array_map( 'trim', $statuses ); $statuses = array_map( array( $this, 'sanitize_text_field' ), $statuses ); $statuses = array_unique( array_filter( $statuses ) ); sort( $statuses ); if ( $array ) { return $statuses; } return implode( $delimator, $statuses ); } public function GetBuyerAllowedStatuses( $pending = false ) { $statuses = $this->GetAllStatuses( $pending ); $order_status_settings = (array) $this->Options( 'order_status', array() ); $allowed_statuses = array(); foreach ( (array) $statuses as $status_val => $status_name ) { if ( in_array( $status_val, array_keys( $order_status_settings ) ) ) { $allowed_statuses[ $status_val ] = $status_name; } } return $allowed_statuses; } public function MaybeVariableProductTitle( $product ) { $product_id = $this->ProductId( $product ); if ( ! is_object( $product ) ) { $product = wc_get_product( $product ); } $attributes = $this->ProductProp( $product, 'variation_attributes' ); $parent_id = $this->ProductProp( $product, 'parent_id' ); if ( ! empty( $attributes ) && ! empty( $parent_id ) ) { $parent = wc_get_product( $parent_id ); $variation_attributes = $this->ProductProp( $parent, 'variation_attributes' ); $variable_title = array(); foreach ( (array) $attributes as $attribute_name => $options ) { $attribute_name = str_ireplace( 'attribute_', '', $attribute_name ); foreach ( (array) $variation_attributes as $key => $value ) { $key = str_ireplace( 'attribute_', '', $key ); if ( sanitize_title( $key ) == sanitize_title( $attribute_name ) ) { $attribute_name = $key; break; } } //if ( ! empty( $options ) && substr( strtolower( $attribute_name ), 0, 3 ) !== 'pa_' ) { if ( ! empty( $options ) ) { if(substr( strtolower( $attribute_name ), 0, 3 ) == 'pa_' ){ $str = ['pa_','-']; $rplc =['',' ']; $attribute_name = str_replace($str,$rplc,$attribute_name); $options = str_replace("-","",$options); } $variable_title[] = $attribute_name . ':' . $options; } } $product_title = get_the_title( $parent_id ); if ( ! empty( $variable_title ) ) { $product_title .= ' (' . implode( ' - ', $variable_title ) . ')'; } } else { $product_title = get_the_title( $product_id ); } return html_entity_decode( urldecode( $product_title ) ); } public function MayBeVariable( $product ) { $product_id = $this->ProductId( $product ); $product = wc_get_product( $product_id ); if ( $product->is_type( 'variable' ) ) { unset( $product_id ); $product_ids = array(); foreach ( (array) $this->ProductProp( $product, 'children' ) as $product_id ) { //$product_ids[] = wc_get_product( $product_id ); $product_ids[] = $product_id; } return $product_ids;//array } else { return $product_id;//int } } public function ProductHasProp( $product, $prop ) { $check = true; $product_ids = (array) $this->MayBeVariable( $product ); foreach ( $product_ids as $product_id ) { $product = wc_get_product( $product_id ); if ( $prop == 'is_not_low_stock' ) { if ( $check = ( WooNotify()->IsStockManaging( $product ) && $product->is_in_stock() && $this->ProductStockQty( $product_id ) > get_option( 'woocommerce_notify_low_stock_amount' ) ) ) { break; } } elseif ( method_exists( $product, $prop ) ) { $check = $check && $product->$prop(); } else { $check = false; } } return $check; } public function ProductSalePriceTime( $product, $type = '' ) { if ( is_numeric( $product ) ) { $product_id = $product; $product = wc_get_product( $product_id ); } else { $product_id = $this->ProductId( $product ); } $timestamp = ''; $method = 'get_date_on_sale_' . $type; if ( method_exists( $product, $method ) ) { $timestamp = $product->$method(); if ( method_exists( $timestamp, 'getOffsetTimestamp' ) ) { $timestamp = $timestamp->getOffsetTimestamp(); } else { $timestamp = ''; } } if ( empty( $timestamp ) ) { $timestamp = get_post_meta( $product_id, '_sale_price_dates_' . $type, true ); } return $timestamp; } public static function multiSelectAndCheckbox( $field, $key, $args, $value ) { $after = ! empty( $args['clear'] ) ? '
' : ''; if ( $args['required'] ) { $args['class'][] = 'validate-required'; $required = ' *'; } else { $required = ''; } $custom_attributes = array(); if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) { foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) { $custom_attributes[] = ( $attribute ) . '="' . ( $attribute_value ) . '"'; } } if ( $args['type'] == "WooNotify_multiselect" ) { $value = is_array( $value ) ? $value : array( $value ); if ( ! empty( $args['options'] ) ) { $options = ''; foreach ( $args['options'] as $option_key => $option_text ) { $options .= ''; } $field = ''; if ( $args['label'] ) { $field .= ''; } $field .= ''; if ( $args['description'] ) { $field .= '' . ( $args['description'] ) . ''; } $field .= '
' . $after; } } if ( $args['type'] == "WooNotify_multicheckbox" ) { $value = is_array( $value ) ? $value : array( $value ); if ( ! empty( $args['options'] ) ) { $field .= '';
if ( $args['label'] ) {
$field .= '';
}
foreach ( $args['options'] as $option_key => $option_text ) {
$field .= '';
$field .= '
';
}
if ( $args['description'] ) {
$field .= '' . ( $args['description'] ) . '';
}
$field .= '
'; echo ''; echo '
'; } public function Meta_Saved_Mobile( $meta, $post_id = 0, $empty_array = array() ) { if ( empty( $post_id ) ) { global $post; $post_id = is_object( $post ) && ! empty( $post->ID ) ? $post->ID : 0; } if ( empty( $post_id ) ) { return $empty_array; } $data = get_post_meta( $post_id, '_WooNotify_product_admin_meta_' . $meta, true ); if ( ! empty( $data ) ) { return (array) $data;//mobile and statuses that set via admin } return $post_id; } public function User_Meta_Mobile( $post_id = 0 ) { $meta = 'user'; $empty_array = array( 'meta' => $meta, 'mobile' => '', 'statuses' => '' ); $data = $this->Meta_Saved_Mobile( $meta, $post_id, $empty_array ); if ( is_array( $data ) ) { return $data; } $meta_key = $this->Options( "product_admin_{$meta}_meta" ); if ( empty( $meta_key ) ) { unset( $empty_array['meta'] ); return $empty_array; } $post_id = absint( $data ); $post = get_post( $post_id ); if ( empty( $post->post_author ) ) { return $empty_array; } return array( 'meta' => $meta, 'mobile' => get_user_meta( $post->post_author, $meta_key, true ), 'statuses' => $this->Options( 'product_admin_meta_order_status' ) ); } public function Post_Meta_Mobile( $post_id = 0 ) { $meta = 'post'; $empty_array = array( 'meta' => $meta, 'mobile' => '', 'statuses' => '' ); $data = $this->Meta_Saved_Mobile( $meta, $post_id, $empty_array ); if ( is_array( $data ) ) { return $data; } $meta_key = $this->Options( "product_admin_{$meta}_meta" ); if ( empty( $meta_key ) ) { unset( $empty_array['meta'] ); return $empty_array; } $post_id = absint( $data ); return array( 'meta' => $meta, 'mobile' => get_post_meta( $post_id, $meta_key, true ), 'statuses' => $this->Options( 'product_admin_meta_order_status' ) ); } public function mayBeJalaliDate( $date_time ) { if ( empty( $date_time ) ) { return ''; } $_date_time = explode( ' ', $date_time ); $date = ! empty( $_date_time[0] ) ? explode( '-', $_date_time[0], 3 ) : ''; $time = ! empty( $_date_time[1] ) ? $_date_time[1] : ''; if ( count( $date ) != 3 || $date[0] < 2000 ) { return $date_time; } list( $year, $month, $day ) = $date; $date = $this->JalaliDate( $year, $month, $day, '/' ) . ' - ' . $time; return trim( trim( $date ), '- ' ); } //از سایت jdf public function JalaliDate( $g_y, $g_m, $g_d, $mod = '' ) { $d_4 = $g_y % 4; $g_a = array( 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ); $doy_g = $g_a[ (int) $g_m ] + $g_d; if ( $d_4 == 0 and $g_m > 2 ) { $doy_g ++; } $d_33 = (int) ( ( ( $g_y - 16 ) % 132 ) * .0305 ); $a = ( $d_33 == 3 or $d_33 < ( $d_4 - 1 ) or $d_4 == 0 ) ? 286 : 287; $b = ( ( $d_33 == 1 or $d_33 == 2 ) and ( $d_33 == $d_4 or $d_4 == 1 ) ) ? 78 : ( ( $d_33 == 3 and $d_4 == 0 ) ? 80 : 79 ); if ( (int) ( ( $g_y - 10 ) / 63 ) == 30 ) { $a --; $b ++; } if ( $doy_g > $b ) { $jy = $g_y - 621; $doy_j = $doy_g - $b; } else { $jy = $g_y - 622; $doy_j = $doy_g + $a; } if ( $doy_j < 187 ) { $jm = (int) ( ( $doy_j - 1 ) / 31 ); $jd = $doy_j - ( 31 * $jm ++ ); } else { $jm = (int) ( ( $doy_j - 187 ) / 30 ); $jd = $doy_j - 186 - ( $jm * 30 ); $jm += 7; } $jd = $jd > 9 ? $jd : '0' . $jd; $jm = $jm > 9 ? $jm : '0' . $jm; return ( $mod == '' ) ? array( $jy, $jm, $jd ) : $jy . $mod . $jm . $mod . $jd; } public function ReplaceShortCodes( $content, $order_status, $order, $vendor_items_array = array() ) { $order_id = $this->OrderId( $order ); $price = strip_tags( $this->OrderProp( $order, 'formatted_order_total', array( '', false ) ) ); $price = html_entity_decode( $price ); $all_product_list = $this->AllItems( $order ); $all_product_ids = ! empty( $all_product_list['product_ids'] ) ? $all_product_list['product_ids'] : array(); $all_items = ! empty( $all_product_list['items'] ) ? $all_product_list['items'] : array(); $all_items_qty = ! empty( $all_product_list['items_qty'] ) ? $all_product_list['items_qty'] : array(); $vendor_product_ids = ! empty( $vendor_items_array['product_ids'] ) ? $vendor_items_array['product_ids'] : array(); $vendor_items = ! empty( $vendor_items_array['items'] ) ? $vendor_items_array['items'] : array(); $vendor_items_qty = ! empty( $vendor_items_array['items_qty'] ) ? $vendor_items_array['items_qty'] : array(); $vendor_price = ! empty( $vendor_items_array['price'] ) ? array_sum( (array) $vendor_items_array['price'] ) : 0; $vendor_price = strip_tags( wc_price( $vendor_price ) ); $payment_gateways = array(); if ( WC()->payment_gateways() ) { $payment_gateways = WC()->payment_gateways->payment_gateways(); } $payment_method = $this->OrderProp( $order, 'payment_method' ); $payment_method = ( isset( $payment_gateways[ $payment_method ] ) ? esc_html( $payment_gateways[ $payment_method ]->get_title() ) : esc_html( $payment_method ) ); $shipping_method = esc_html( $this->OrderProp( $order, 'shipping_method' ) ); $country = WC()->countries; $bill_country = ( isset( $country->countries[ $this->OrderProp( $order, 'billing_country' ) ] ) ) ? $country->countries[ $this->OrderProp( $order, 'billing_country' ) ] : $this->OrderProp( $order, 'billing_country' ); $bill_state = ( $this->OrderProp( $order, 'billing_country' ) && $this->OrderProp( $order, 'billing_state' ) && isset( $country->states[ $this->OrderProp( $order, 'billing_country' ) ][ $this->OrderProp( $order, 'billing_state' ) ] ) ) ? $country->states[ $this->OrderProp( $order, 'billing_country' ) ][ $this->OrderProp( $order, 'billing_state' ) ] : $this->OrderProp( $order, 'billing_state' ); $shipp_country = ( isset( $country->countries[ $this->OrderProp( $order, 'shipping_country' ) ] ) ) ? $country->countries[ $this->OrderProp( $order, 'shipping_country' ) ] : $this->OrderProp( $order, 'shipping_country' ); $shipp_state = ( $this->OrderProp( $order, 'shipping_country' ) && $this->OrderProp( $order, 'shipping_state' ) && isset( $country->states[ $this->OrderProp( $order, 'shipping_country' ) ][ $this->OrderProp( $order, 'shipping_state' ) ] ) ) ? $country->states[ $this->OrderProp( $order, 'shipping_country' ) ][ $this->OrderProp( $order, 'shipping_state' ) ] : $this->OrderProp( $order, 'shipping_state' ); $post = get_post( $order_id ); $tags = array( '{b_first_name}' => $this->OrderProp( $order, 'billing_first_name' ), '{b_last_name}' => $this->OrderProp( $order, 'billing_last_name' ), '{b_company}' => $this->OrderProp( $order, 'billing_company' ), '{b_address_1}' => $this->OrderProp( $order, 'billing_address_1' ), '{b_address_2}' => $this->OrderProp( $order, 'billing_address_2' ), '{b_state}' => $bill_state, '{b_city}' => $this->OrderProp( $order, 'billing_city' ), '{b_postcode}' => $this->OrderProp( $order, 'billing_postcode' ), '{b_country}' => $bill_country, '{sh_first_name}' => $this->OrderProp( $order, 'shipping_first_name' ), '{sh_last_name}' => $this->OrderProp( $order, 'shipping_last_name' ), '{sh_company}' => $this->OrderProp( $order, 'shipping_company' ), '{sh_address_1}' => $this->OrderProp( $order, 'shipping_address_1' ), '{sh_address_2}' => $this->OrderProp( $order, 'shipping_address_2' ), '{sh_state}' => $shipp_state, '{sh_city}' => $this->OrderProp( $order, 'shipping_city' ), '{sh_postcode}' => $this->OrderProp( $order, 'shipping_postcode' ), '{sh_country}' => $shipp_country, '{phone}' => get_post_meta( $order_id, '_billing_phone', true ), '{mobile}' => $this->buyerMobile( $order_id ), '{email}' => $this->OrderProp( $order, 'billing_email' ), '{order_id}' => $this->OrderProp( $order, 'order_number' ), '{date}' => $this->OrderDate( $order ), '{post_id}' => $order_id, '{status}' => $this->statusName( $order_status, true ), '{price}' => $price, '{total_discount}'=> strip_tags( wc_price( $this->OrderProp( $order, 'total_discount' ) ) ), '{total_tax}' => strip_tags( wc_price( $this->OrderProp( $order, 'total_tax' ) ) ), '{subtotal}' => strip_tags( wc_price( $this->OrderProp( $order, 'subtotal' ) ) ), '{all_items}' => implode( ' - ', $all_items ), '{all_items_qty}' => implode( ' - ', $all_items_qty ), '{count_items}' => count( $all_items ), '{vendor_items}' => implode( ' - ', $vendor_items ), '{vendor_items_qty}' => implode( ' - ', $vendor_items_qty ), '{count_vendor_items}' => count( $vendor_items ), '{vendor_price}' => $vendor_price, '{transaction_id}' => get_post_meta( $order_id, '_transaction_id', true ), '{payment_method}' => $payment_method, '{shipping_method}' => $shipping_method, '{description}' => nl2br( esc_html( $post->post_excerpt ) ), ); $content = apply_filters( 'WooNotify_order_360Messenger_body_before_replace', $content, array_keys( $tags ), array_values( $tags ), $order_id, $order, $all_product_ids, $vendor_product_ids ); $content = str_ireplace( array_keys( $tags ), array_values( $tags ), $content ); $content = str_ireplace( array( '