@@ -283,3 +283,34 @@ function clwc_earning_points_money_spent() {
283
283
284
284
return apply_filters ( 'clwc_earning_points_money_spent ' , $ money_spent );
285
285
}
286
+
287
+ /**
288
+ * Insert a loyalty log entry into the database.
289
+ *
290
+ * @since 2.0.0
291
+ *
292
+ * @param int $user_id The user ID.
293
+ * @param string $name The customer's name.
294
+ * @param string $email The customer's email.
295
+ * @param int $points The number of points for the action.
296
+ * @param string $details Details about the action (e.g., "Points redeemed for discount").
297
+ * @return bool|int The inserted row ID on success, or false on failure.
298
+ */
299
+ function clwc_insert_loyalty_log_entry ( $ user_id , $ name , $ email , $ points , $ details ) {
300
+ global $ wpdb ;
301
+
302
+ $ table_name = $ wpdb ->prefix . 'clwc_loyalty_log ' ;
303
+
304
+ // Prepare data and sanitize for database insertion.
305
+ $ data = [
306
+ 'user_id ' => absint ( $ user_id ),
307
+ 'name ' => sanitize_text_field ( $ name ),
308
+ 'email ' => sanitize_email ( $ email ),
309
+ 'points ' => intval ( $ points ),
310
+ 'details ' => sanitize_textarea_field ( $ details ),
311
+ 'date ' => current_time ( 'mysql ' ),
312
+ ];
313
+
314
+ // Insert the data into the table.
315
+ return $ wpdb ->insert ( $ table_name , $ data );
316
+ }
0 commit comments