'groups', 'message' => 'error' ) ) ); exit; } $data = array( 'name' => $name, 'discount_percent' => $percent, ); if ( $id ) { WC_EDM_DB::update_group( $id, $data ); } else { $id = WC_EDM_DB::insert_group( $data ); } if ( $id ) { WC_EDM_DB::set_group_categories( $id, $category_ids ); } wp_safe_redirect( WC_EDM_Helpers::admin_url( array( 'tab' => 'groups', 'message' => $id ? 'saved' : 'error' ) ) ); exit; } // Delete. if ( isset( $_GET['action'], $_GET['id'] ) && 'delete' === $_GET['action'] ) { $id = absint( $_GET['id'] ); check_admin_referer( 'wc_edm_delete_group_' . $id ); WC_EDM_DB::delete_group( $id ); wp_safe_redirect( WC_EDM_Helpers::admin_url( array( 'tab' => 'groups', 'message' => 'deleted' ) ) ); exit; } } /** * Render the groups tab (list or edit form). */ public function render() { $action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( 'new' === $action || 'edit' === $action ) { $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $this->render_form( $id ); return; } $this->render_list(); } /** * Render the list of groups. */ private function render_list() { $groups = WC_EDM_DB::get_groups(); ?>
| name ); ?> | discount_percent ) ); ?>% | ' . esc_html__( 'None', 'wc-email-discount' ) . ''; ?> |
' . esc_html__( 'Group not found.', 'wc-email-discount' ) . '
'; return; } ?>