'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(); ?>

id ); $names = array(); foreach ( $category_ids as $category_id ) { $term = get_term( $category_id, 'product_cat' ); if ( $term && ! is_wp_error( $term ) ) { $names[] = $term->name; } } $edit_url = WC_EDM_Helpers::admin_url( array( 'tab' => 'groups', 'action' => 'edit', 'id' => (int) $group->id ) ); $delete_url = wp_nonce_url( WC_EDM_Helpers::admin_url( array( 'tab' => 'groups', 'action' => 'delete', 'id' => (int) $group->id ) ), 'wc_edm_delete_group_' . (int) $group->id ); ?>
name ); ?> discount_percent ) ); ?>% ' . esc_html__( 'None', 'wc-email-discount' ) . ''; ?>
term_id ] = $category; } if ( $id && ! $group ) { echo '

' . esc_html__( 'Group not found.', 'wc-email-discount' ) . '

'; return; } ?>