softoba_init_posttype(); $this->softoba_init_post_statuses(); } public function softoba_init_posttype() { $labels = array( 'name' => esc_html_x( 'Return Requests', 'Page title', 'astra' ), 'singular_name' => esc_html_x( 'Return Request', 'Post type singular name', 'astra' ), 'menu_name' => esc_html_x( 'Return Requests', 'admin menu', 'astra' ), 'name_admin_bar' => esc_html_x( 'Return Request', 'add new on admin bar', 'astra' ), 'add_new' => esc_html_x( 'Add New', 'Add New Return request', 'astra' ), 'add_new_item' => esc_html__( 'Add new Return request', 'astra' ), 'new_item' => esc_html__( 'New Return request', 'astra' ), 'edit_item' => esc_html__( 'Manage Return request', 'astra' ), 'view_item' => esc_html__( 'View Return request', 'astra' ), 'all_items' => esc_html__( 'All Return requests', 'astra' ), 'search_items' => esc_html__( 'Search Return requests', 'astra' ), 'parent_item_colon' => esc_html__( 'Parent Return requests:', 'astra' ), 'not_found' => esc_html__( 'No Return request found.', 'astra' ), 'not_found_in_trash' => esc_html__( 'No Return requests found in Trash.', 'astra' ) ); $args = array( 'hierarchical' => false, 'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'menu_position' => 58, 'can_export' => false, 'has_archive' => false, 'exclude_from_search' => true, 'menu_icon' => 'dashicons-money', 'query_var' => false, 'labels' => $labels, 'description' => esc_html__( 'Description.', 'astra' ), 'publicly_queryable' => true, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => 'do_not_allow' ), 'map_meta_cap' => true, 'supports' => array( 'title' ) ); $exchange_labels = array( 'name' => esc_html_x( 'Exchange Requests', 'Page title', 'astra' ), 'singular_name' => esc_html_x( 'Exchange Request', 'Post type singular name', 'astra' ), 'menu_name' => esc_html_x( 'Exchange Requests', 'admin menu', 'astra' ), 'name_admin_bar' => esc_html_x( 'Exchange Request', 'add new on admin bar', 'astra' ), 'add_new' => esc_html_x( 'Add New', 'Add New Exchange request', 'astra' ), 'add_new_item' => esc_html__( 'Add new Exchange request', 'astra' ), 'new_item' => esc_html__( 'New Exchange request', 'astra' ), 'edit_item' => esc_html__( 'Manage Exchange request', 'astra' ), 'view_item' => esc_html__( 'View Exchange request', 'astra' ), 'all_items' => esc_html__( 'All Exchange requests', 'astra' ), 'search_items' => esc_html__( 'Search Exchange requests', 'astra' ), 'parent_item_colon' => esc_html__( 'Parent Exchange requests:', 'astra' ), 'not_found' => esc_html__( 'No Exchange request found.', 'astra' ), 'not_found_in_trash' => esc_html__( 'No Exchange requests found in Trash.', 'astra' ) ); $exchange_args = array( 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false, 'menu_position' => 59, 'can_export' => false, 'has_archive' => true, 'exclude_from_search' => true, 'menu_icon' => 'dashicons-share-alt2', 'query_var' => false, 'labels' => $exchange_labels, 'description' => esc_html__( 'Description.', 'astra' ), 'publicly_queryable' => true, 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => 'do_not_allow' ), 'map_meta_cap' => true, 'supports' => array( 'title' ) ); register_post_type( SOFTOBA_RETURN_POST_TYPE, $args ); register_post_type( SOFTOBA_EXCHANGE_POST_TYPE, $exchange_args ); } public function softoba_init_post_statuses() { register_post_status( 'softoba-new', array( 'label' => esc_html__( 'New Return request', 'astra' ), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( esc_html__( 'New', 'astra' ) . ' (%s)', esc_html__( 'New', 'astra' ) . ' (%s)' ), ) ); register_post_status( 'softoba-processing', array( 'label' => esc_html__( 'Processing Return request', 'astra' ), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( esc_html__( 'Processing', 'astra' ) . ' (%s)', esc_html__( 'Processing', 'astra' ) . ' (%s)' ), )); register_post_status( 'softoba-on-hold', array( 'label' => esc_html__( 'Return request on hold', 'astra' ), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( esc_html__( 'On Hold', 'astra' ) . ' (%s)', esc_html__( 'On Hold', 'astra' ) . ' (%s)' ), )); register_post_status( 'softoba-approved', array( 'label' => esc_html__( 'Return request approved', 'astra' ), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( esc_html__( 'Approved', 'astra' ) . ' (%s)', esc_html__( 'Approved', 'astra' ) . ' (%s)' ), )); register_post_status( 'softoba-rejected', array( 'label' => esc_html__( 'Return request rejected', 'astra' ), 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop( esc_html__( 'Rejected', 'astra' ) . ' (%s)', esc_html__( 'Rejected', 'astra' ) . ' (%s)' ), )); register_post_status('wc-softoba-exchange-approve', array( 'label' => 'Exchange Approved', 'public' => true, 'exclude_from_search' => false, 'show_in_admin_all_list' => true, 'show_in_admin_status_list' => true, 'label_count' => _n_noop('Exchange Approved (%s)', 'Exchange Approved (%s)'), )); // register_post_status('wc-softoba-exchange-request', array( // 'label' => 'Exchange Requested', // 'public' => true, // 'exclude_from_search' => false, // 'show_in_admin_all_list' => true, // 'show_in_admin_status_list' => true, // 'label_count' => _n_noop('Exchange Requested (%s)', 'Exchange Requested (%s)') // )); } // Remove view link for custom post type 'return_request' public function softoba_remove_return_request_view_link($actions, $post) { if ( $post->post_type === SOFTOBA_RETURN_POST_TYPE ) { unset($actions['view']); unset($actions['inline hide-if-no-js']); }elseif( $post->post_type === SOFTOBA_EXCHANGE_POST_TYPE ){ unset($actions['view']); unset($actions['inline hide-if-no-js']); } return $actions; } public function add_cpt_columns( $posts_columns ) { unset( $posts_columns['title'] ); unset( $posts_columns['date'] ); $posts_columns['title'] = esc_html__( 'Title', 'astra' ); $posts_columns['order'] = esc_html__( 'Order', 'astra' ); $posts_columns['customer'] = esc_html__( 'Customer', 'astra' ); $posts_columns['product'] = esc_html__( 'Product', 'astra' ); $posts_columns['date'] = esc_html__( 'Date', 'astra' ); return $posts_columns; } public function add_cpt_columns_content( $column_name, $post_id ) { if ( ! $post_id ) { return; } $request = new SOFTOBA_Return_Request( $post_id ); if ( ! $request->exists() ) { return; } if ( $column_name == 'order') { if ( $request->order_id ) { $order_number = wc_get_order( $request->order_id )->get_order_number(); echo '' . '#' . $order_number . ''; } } if ( $column_name == 'product') { if ( $request->products_data ) { foreach( $request->products_data['products'] as $ex_product) { $product = wc_get_product( $ex_product['product_id'] ); $id = softoba_get_base_product_id( $product ); if ( $product && $product->exists() ) { echo '' . $product->get_formatted_name() . ' -- '; } else { echo '' . esc_html__( 'N/A', 'astra' ) . ''; } } } } if ( $column_name == 'customer') { if ( $request->customer_id ) { echo version_compare( WC()->version, '3.0.0', '<' ) ? $request->get_customer_link_legacy() : $request->get_customer_link(); } } } public function add_exchange_cpt_columns( $posts_columns ) { unset( $posts_columns['title'] ); unset( $posts_columns['date'] ); $posts_columns['title'] = esc_html__( 'Title', 'astra' ); $posts_columns['exchange_fee'] = esc_html__( 'Exchange Fee', 'astra' ); $posts_columns['order'] = esc_html__( 'Order', 'astra' ); $posts_columns['customer'] = esc_html__( 'Customer', 'astra' ); $posts_columns['product'] = esc_html__( 'Product', 'astra' ); $posts_columns['date'] = esc_html__( 'Date', 'astra' ); return $posts_columns; } public function add_exchange_cpt_columns_content( $column_name, $post_id ) { if ( ! $post_id ) { return; } $request = new SOFTOBA_Exchange_Request( $post_id ); if ( ! $request->exists() ) { return; } if( $column_name == 'exchange_fee' ) { if( $request->exchange_fee === 'on-hold' ) { echo 'On hold'; }elseif( $request->exchange_fee === 'processing' || $request->exchange_fee === 'completed' ){ echo 'Paid'; }else{ echo 'Unpaid'; } } if ( $column_name == 'order') { if ( $request->order_id ) { $order_number = wc_get_order( $request->order_id )->get_order_number(); echo '' . '#' . $order_number . ''; } } if ( $column_name == 'product') { if ( $request->products_data ) { foreach( $request->products_data['products'] as $ex_product) { $product = wc_get_product( $ex_product['product_id'] ); $id = softoba_get_base_product_id( $product ); if ( $product && $product->exists() ) { echo '' . $product->get_formatted_name() . ' -- '; } else { echo '' . esc_html__( 'N/A', 'astra' ) . ''; } } } } if ( $column_name == 'customer') { if ( $request->customer_id ) { echo version_compare( WC()->version, '3.0.0', '<' ) ? $request->get_customer_link_legacy() : $request->get_customer_link(); } } } public function manage_meta_boxes( $post_type, $post ) { if ( $post_type && SOFTOBA_RETURN_POST_TYPE == $post_type ) { remove_meta_box( 'submitdiv', SOFTOBA_RETURN_POST_TYPE, 'side' ); add_meta_box( 'softoba-info-metabox', esc_html__( 'Request info', 'astra' ), array( $this, 'softoba_info_metabox_content' ), SOFTOBA_RETURN_POST_TYPE, 'side', 'core' ); add_meta_box( 'softoba-items-metabox', esc_html__( 'Items', 'astra' ), array( $this, 'softoba_items_metabox_content' ), SOFTOBA_RETURN_POST_TYPE, 'normal', 'core' ); } if ( $post_type && $post && 'shop_order' == $post_type ) { $order = wc_get_order( $post ); $requests = softoba_get_prop( $order, 'softoba_return_requests', true ); if ( $requests ) { add_meta_box( 'softoba-manage-return-requests', esc_html__( 'Return Request', 'astra' ), array( $this, 'softoba_manage_return_requests_content' ), 'shop_order', 'side', 'core' ); } } } /** * Exchange Post type metaboxes * * @param [SOFTOBA_EXCHANGE_POST_TYPE] $post_type * @param [type] $post * @return void */ public function manage_exchange_meta_boxes( $post_type, $post ) { if ( $post_type && SOFTOBA_EXCHANGE_POST_TYPE == $post_type ) { remove_meta_box( 'submitdiv', SOFTOBA_EXCHANGE_POST_TYPE, 'side' ); add_meta_box( 'softoba-info-metabox', esc_html__( 'Request info', 'astra' ), array( $this, 'softoba_exchange_info_metabox_content' ), SOFTOBA_EXCHANGE_POST_TYPE, 'side', 'core' ); add_meta_box( 'softoba-items-metabox', esc_html__( 'Items', 'astra' ), array( $this, 'softoba_exchange_items_metabox_content' ), SOFTOBA_EXCHANGE_POST_TYPE, 'normal', 'core' ); } if ( $post_type && $post && 'shop_order' == $post_type ) { $order = wc_get_order( $post ); $requests = softoba_get_prop( $order, 'softoba_exchange_requests', true ); if ( $requests ) { // add_meta_box( 'softoba-manage-exchange-requests', // esc_html__( 'Exchange Request', 'astra' ), // array( $this, 'softoba_manage_exchange_requests_content' ), 'shop_order', 'side', 'core' // ); } } } public function softoba_items_metabox_content( $post ) { if ( ! $post ) { return; } wc_get_template( 'admin/softoba-items-table.php', array( 'post' => $post ), '', SOFTOBA_TEMPLATE_PATH . '/' ); } public function softoba_exchange_items_metabox_content( $post ) { if ( ! $post ) { return; } wc_get_template( 'admin/softoba-exchange-items-table.php', array( 'post' => $post ), '', SOFTOBA_TEMPLATE_PATH . '/' ); } public function softoba_info_metabox_content( $post ) { if ( ! $post ) { return; } $request = new SOFTOBA_Return_Request( $post->ID ); if ( ! ( $request instanceof SOFTOBA_Return_Request && $request->exists() ) ) { return; } ?>
- refund_total ); ?> |
get_title(); ?> |