idm_asw_current_page(); self::$current_tab = self::$asw_admin_obj->idm_asw_current_tab(); self::$post_type = ASW_POST_TYPE; self::$message = ''; add_action( 'idm_cart_products_specific_rule', array( $this, 'idm_asw_based_on_cart' ), 10, 2 ); add_action( 'idm_location_specific_rule', array( $this, 'idm_asw_based_on_location' ), 10, 2 ); add_action( 'idm_cart_specific_rule', array( $this, 'idm_asw_based_on_cart_specific' ), 10, 2 ); add_action( 'idm_checkout_specific_rule', array( $this, 'idm_asw_based_on_checkout_specific' ), 10, 2 ); add_action( 'idm_user_specific_rule', array( $this, 'idm_asw_based_on_user_specific' ), 10, 2 ); add_action( 'idm_product_specific_rule', array( $this, 'idm_asw_based_on_product_specific' ), 10, 2 ); add_action( 'idm_add_new_shipping_btn', array( $this, 'idm_add_new_shipping_btn_fn' ), 10, 2 ); } /** * Display output. * * @since 1.0.0 * * @uses asw_sms_save_method * @uses asw_sms_add_shipping_method_form * @uses asw_sms_edit_method_screen * @uses asw_sms_delete_method * @uses asw_sms_duplicate_method * @uses asw_sms_list_methods_screen * @uses ASW_Admin::idm_asw_updated_message() */ public static function asw_sms_output() { $action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING ); $post_id_request = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT ); $asw_nonce = filter_input( INPUT_GET, 'asw_nonce', FILTER_SANITIZE_STRING ); $get_asw_add = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING ); self::$current_tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING ); self::$message = filter_input( INPUT_GET, 'message', FILTER_SANITIZE_STRING ); if ( isset( $action ) && !empty($action) ) { if ( 'add' === $action ) { self::asw_sms_save_method(); self::asw_sms_add_shipping_method_form(); } elseif ( 'edit' === $action ) { if ( isset( $asw_nonce ) && !empty($asw_nonce) ) { $getnonce = wp_verify_nonce( $asw_nonce, 'edit_' . $post_id_request ); if ( isset( $getnonce ) && 1 === $getnonce ) { self::asw_sms_edit_method_screen( $post_id_request ); } else { wp_safe_redirect( add_query_arg( array( 'page' => 'asw-main', 'tab' => 'shipping_section', ), admin_url( 'admin.php' ) ) ); exit; } } elseif ( isset( $get_asw_add ) && !empty($get_asw_add) ) { if ( !wp_verify_nonce( $get_asw_add, 'asw_add' ) ) { self::$message = 'nonce_check'; } else { self::asw_sms_edit_method_screen( $post_id_request ); } } } elseif ( 'delete' === $action ) { self::asw_sms_delete_method( $post_id_request ); } elseif ( 'duplicate' === $action ) { self::asw_sms_duplicate_method( $post_id_request ); } else { self::asw_sms_list_methods_screen(); } } else { self::asw_sms_list_methods_screen(); } } /** * Delete shipping method. * * @param int $id Get shipping method id. * * @uses Advanced_Easy_Shipping_For_WooCommerce::idm_asw_updated_message() * * @since 1.0.0 */ public function asw_sms_delete_method( $id ) { $asw_nonce = filter_input( INPUT_GET, 'asw_nonce', FILTER_SANITIZE_STRING ); $get_tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING ); $getnonce = wp_verify_nonce( $asw_nonce, 'del_' . $id ); if ( isset( $getnonce ) && 1 === $getnonce ) { wp_delete_post( $id ); $delet_action_redirect_url = self::$asw_admin_obj->idm_dynamic_url( self::$current_page, self::$current_tab, '', '', '', 'deleted' ); wp_safe_redirect( $delet_action_redirect_url ); exit; } else { self::$asw_admin_obj->idm_asw_updated_message( 'nonce_check', $get_tab, '' ); } } /** * Duplicate shipping method. * * @param int $id Get shipping method id. * * @uses Advanced_Easy_Shipping_For_WooCommerce::idm_asw_updated_message() * * @since 1.0.0 */ public function asw_sms_duplicate_method( $id ) { $asw_nonce = filter_input( INPUT_GET, 'asw_nonce', FILTER_SANITIZE_STRING ); $get_tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING ); $getnonce = wp_verify_nonce( $asw_nonce, 'duplicate_' . $id ); $asw_add = wp_create_nonce( 'asw_add' ); $post_id = ( isset( $id ) ? absint( $id ) : '' ); $new_post_id = ''; if ( isset( $getnonce ) && 1 === $getnonce ) { if ( !empty($post_id) || '' !== $post_id ) { $post = get_post( $post_id ); $current_user = wp_get_current_user(); $new_post_author = $current_user->ID; if ( isset( $post ) && null !== $post ) { $args = array( 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_name' => $post->post_name, 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => 'draft', 'post_title' => $post->post_title . '-duplicate', 'post_type' => self::$post_type, 'to_ping' => $post->to_ping, 'menu_order' => $post->menu_order, ); $new_post_id = wp_insert_post( $args ); $post_meta_data = get_post_meta( $post_id ); if ( 0 !== count( $post_meta_data ) ) { foreach ( $post_meta_data as $meta_key => $meta_data ) { if ( '_wp_old_slug' === $meta_key ) { continue; } if ( is_array( $meta_data[0] ) ) { $meta_value = maybe_unserialize( $meta_data[0] ); } else { $meta_value = $meta_data[0]; } update_post_meta( $new_post_id, $meta_key, $meta_value ); } } } $duplicat_action_redirect_url = self::$asw_admin_obj->idm_dynamic_url( self::$current_page, self::$current_tab, 'edit', $new_post_id, esc_attr( $asw_add ), 'duplicated' ); wp_safe_redirect( $duplicat_action_redirect_url ); exit; } else { $action_redirect_url = self::$asw_admin_obj->idm_dynamic_url( self::$current_page, self::$current_tab, '', '', '', 'failed' ); wp_safe_redirect( $action_redirect_url ); exit; } } else { self::$asw_admin_obj->idm_asw_updated_message( 'nonce_check', $get_tab, '' ); } } /** * Count total shipping method. * * @return int $count_method Count total shipping method ID. * * @since 1.0.0 */ public static function aswsmp_sm_count_method() { $shipping_method_args = array( 'post_type' => self::$post_type, 'post_status' => array( 'publish', 'draft' ), 'posts_per_page' => -1, 'orderby' => 'ID', 'order' => 'DESC', ); $sm_post_query = new WP_Query( $shipping_method_args ); $shipping_method_list = $sm_post_query->posts; return count( $shipping_method_list ); } /** * Save shipping method when add or edit. * * @param int $method_id Shipping method id. * * @return bool false when nonce is not verified. * @uses aswsmp_sm_count_method() * * @since 1.0.0 * * @uses Advanced_Easy_Shipping_For_WooCommerce::idm_asw_updated_message() */ private static function asw_sms_save_method( $method_id = 0 ) { global $sitepress ; $action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING ); $get_tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING ); $asw_save = filter_input( INPUT_POST, 'asw_save', FILTER_SANITIZE_STRING ); $woocommerce_save_method_nonce = filter_input( INPUT_POST, 'woocommerce_save_method_nonce', FILTER_SANITIZE_STRING ); if ( isset( $action ) && !empty($action) ) { if ( isset( $asw_save ) ) { if ( empty($woocommerce_save_method_nonce) || !wp_verify_nonce( sanitize_text_field( $woocommerce_save_method_nonce ), 'woocommerce_save_method' ) ) { self::$asw_admin_obj->idm_asw_updated_message( 'nonce_check', $get_tab, '' ); } $asw_shipping_status = filter_input( INPUT_POST, 'asw_shipping_status', FILTER_SANITIZE_STRING ); $asw_shipping_title = filter_input( INPUT_POST, 'asw_shipping_title', FILTER_SANITIZE_STRING ); $get_asw_gss = filter_input( INPUT_POST, 'asw_gss', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY ); $get_asw_rule_status = filter_input( INPUT_POST, 'asw_rule_status', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY ); $get_asw_condition_name = filter_input( INPUT_POST, 'asw_condition_name', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY ); $get_asw_rule_status_arr = array(); if ( !empty($get_asw_rule_status) ) { foreach ( $get_asw_rule_status as $get_asw_rule_key ) { $get_asw_rule_status_arr[] = $get_asw_rule_key; } } $get_asw_condition_name_arr = array(); if ( !empty($get_asw_condition_name) ) { foreach ( $get_asw_condition_name as $get_asw_condition_key ) { $get_asw_condition_name_arr[] = $get_asw_condition_key; } } if ( !empty($get_asw_rule_status_arr) && !empty($get_asw_condition_name_arr) ) { foreach ( $get_asw_rule_status_arr as $asw_rule_status_value ) { foreach ( $get_asw_condition_name_arr as $asw_condition_name ) { if ( isset( $get_asw_condition_name_arr['asw_condition_name'] ) && strpos( $asw_rule_status_value, $asw_condition_name ) !== false ) { unset( $get_asw_condition_name_arr['asw_condition_name'][$asw_rule_status_value] ); } } } } $shipping_method_count = self::aswsmp_sm_count_method(); $method_id = (int) $method_id; if ( isset( $asw_shipping_status ) ) { $post_status = 'publish'; } else { $post_status = 'draft'; } if ( '' !== $method_id && 0 !== $method_id ) { $fee_post = array( 'ID' => $method_id, 'post_title' => sanitize_text_field( $asw_shipping_title ), 'post_status' => $post_status, 'menu_order' => $shipping_method_count + 1, 'post_type' => self::$post_type, ); $method_id = wp_update_post( $fee_post ); } else { $fee_post = array( 'post_title' => sanitize_text_field( $asw_shipping_title ), 'post_status' => $post_status, 'menu_order' => $shipping_method_count + 1, 'post_type' => self::$post_type, ); $method_id = wp_insert_post( $fee_post ); } if ( '' !== $method_id && 0 !== $method_id ) { if ( $method_id > 0 ) { $easy_shipping_data = array(); $easy_shipping_data['asw_gss'] = $get_asw_gss; $easy_shipping_data['asw_rule_status'] = $get_asw_rule_status; $easy_shipping_data['asw_condition_name'] = $get_asw_condition_name; if ( isset( $easy_shipping_data['asw_gss']['asw_shipping_tooltip'] ) ) { update_post_meta( $method_id, 'asw_shipping_tooltip', $easy_shipping_data['asw_gss']['asw_shipping_tooltip'] ); } if ( isset( $easy_shipping_data['asw_gss']['asw_free_shipping']['asw_free_shipping_title'] ) ) { update_post_meta( $method_id, 'asw_free_shipping_title', $easy_shipping_data['asw_gss']['asw_free_shipping']['asw_free_shipping_title'] ); } if ( isset( $easy_shipping_data['asw_gss']['asw_est_delivery_time'] ) ) { update_post_meta( $method_id, 'asw_est_delivery_time', $easy_shipping_data['asw_gss']['asw_est_delivery_time'] ); } if ( isset( $easy_shipping_data['asw_gss']['asw_est_delivery_time'] ) ) { update_post_meta( $method_id, 'asw_est_delivery_time', $easy_shipping_data['asw_gss']['asw_est_delivery_time'] ); } update_post_meta( $method_id, 'asw_easy_shipping_data', wp_json_encode( $easy_shipping_data ) ); $get_default_lang = idm_asw_get_default_language(); if ( isset( $sitepress ) ) { update_post_meta( $method_id, 'asw_esd_lang_key', $get_default_lang ); } } } else { echo '

' . esc_html__( 'Error saving shipping method.', 'advanced-easy-shipping-for-woocommerce' ) . '

' ; return false; } $asw_add = wp_create_nonce( 'asw_add' ); if ( 'add' === $action ) { $add_action_redirect_url = self::$asw_admin_obj->idm_dynamic_url( self::$current_page, self::$current_tab, 'edit', $method_id, esc_attr( $asw_add ), 'created' ); wp_safe_redirect( $add_action_redirect_url ); exit; } if ( 'edit' === $action ) { $edit_action_redirect_url = self::$asw_admin_obj->idm_dynamic_url( self::$current_page, self::$current_tab, 'edit', $method_id, esc_attr( $asw_add ), 'saved' ); wp_safe_redirect( $edit_action_redirect_url ); exit; } } } } /** * Edit shipping method screen. * * @param string $id Get shipping method id. * * @uses asw_sms_save_method() * @uses asw_sms_edit_method() * * @since 1.0.0 */ public static function asw_sms_edit_method_screen( $id ) { self::asw_sms_save_method( $id ); self::asw_sms_edit_method(); } /** * Edit shipping method. * * @since 1.0.0 */ public static function asw_sms_edit_method() { include ASW_PLUGIN_DIR . '/settings/asw-shipping-settings.php'; } /** * Add new shipping button in shipping list section. * * @param string $link_method_url Link method url. * * @param string $text button text. */ public function idm_add_new_shipping_btn_fn( $link_method_url, $text ) { ?> idm_dynamic_url( self::$current_page, self::$current_tab, 'add', '', '', '' ); ?>

idm_asw_updated_message( self::$message, self::$current_tab, '' ); } ?>
process_bulk_action(); $wc_shipping_methods_table->prepare_items(); $wc_shipping_methods_table->search_box( esc_html__( 'Search Shipping Method', 'advanced-easy-shipping-for-woocommerce' ), 'asw-shipping' ); $wc_shipping_methods_table->display(); ?>
data-gb="" data-name="products">
$asw_cn_value ) { $get_asw_cn_key = $this->asw_get_select_attr_for_selection( $asw_cn_value['condition'] ); $asw_placeholder_decode = json_decode( asw_placeholder_for_fields(), true ); $placeholder_key = ''; if ( $asw_placeholder_decode ) { if ( $get_asw_cn_key ) { $placeholder_key = $asw_placeholder_decode[$get_asw_cn_key]; } } $get_post_type = asw_get_post_type( $get_asw_cn_key ); ?>
+
-
data-gb="">
$asw_cn_value ) { $get_asw_cn_key = $this->asw_get_select_attr_for_selection( $asw_cn_value['condition'] ); $asw_placeholder_decode = json_decode( asw_placeholder_for_fields(), true ); $placeholder_key = ''; if ( $asw_placeholder_decode ) { if ( $get_asw_cn_key ) { $placeholder_key = $asw_placeholder_decode[$get_asw_cn_key]; } } ?>
+
-
data-gb="">
$asw_cn_value ) { $get_asw_cn_key = $this->asw_get_select_attr_for_selection( $asw_cn_value['condition'] ); $asw_placeholder_decode = json_decode( asw_placeholder_for_fields(), true ); $placeholder_key = ''; if ( $asw_placeholder_decode ) { if ( $get_asw_cn_key ) { $placeholder_key = $asw_placeholder_decode[$get_asw_cn_key]; } } ?>
+
-
data-gb="">
data-gb="">
$asw_cn_value ) { $get_asw_cn_key = $this->asw_get_select_attr_for_selection( $asw_cn_value['condition'] ); $asw_placeholder_decode = json_decode( asw_placeholder_for_fields(), true ); $placeholder_key = ''; if ( $asw_placeholder_decode ) { if ( $get_asw_cn_key ) { $placeholder_key = $asw_placeholder_decode[$get_asw_cn_key]; } } ?>
+
-
data-gb="">
$asw_cn_value ) { $get_cart_spec_opt = json_decode( asw_get_based_on_product_specific_options() ); $ut_array = json_decode( asw_per_unit_options( $asw_cn_value['condition'] ) ); $get_apu_id = ''; $get_ut_id = ''; $get_minval = ''; $get_maxval = ''; $get_price = ''; $get_apsub = ''; if ( array_key_exists( 'advanced', $asw_cn_value ) ) { if ( array_key_exists( 'apu', $asw_cn_value['advanced'] ) ) { $get_apu_id = $asw_cn_value['advanced']['apu']; } $get_apu_status = ( !empty($get_apu_id) && 'on' === $get_apu_id ? 'checked' : '' ); if ( array_key_exists( 'ut', $asw_cn_value['advanced'] ) ) { $get_ut_id = $asw_cn_value['advanced']['ut']; } if ( array_key_exists( 'minval', $asw_cn_value['advanced'] ) ) { $get_minval = $asw_cn_value['advanced']['minval']; } if ( array_key_exists( 'maxval', $asw_cn_value['advanced'] ) ) { $get_maxval = $asw_cn_value['advanced']['maxval']; } if ( array_key_exists( 'price', $asw_cn_value['advanced'] ) ) { $get_price = $asw_cn_value['advanced']['price']; } if ( array_key_exists( 'apsub', $asw_cn_value['advanced'] ) ) { $get_apsub = $asw_cn_value['advanced']['apsub']; } } $get_asw_cn_key = $this->asw_get_select_attr_for_selection( $asw_cn_value['condition'] ); $asw_placeholder_decode = json_decode( asw_placeholder_for_fields(), true ); $placeholder_key = ''; if ( $asw_placeholder_decode ) { if ( array_key_exists( $get_asw_cn_key, $asw_placeholder_decode ) ) { $placeholder_key = $asw_placeholder_decode[$get_asw_cn_key]; } } $get_post_type = asw_get_post_type( $get_asw_cn_key ); ?>
>
+
-