Skip to content

Commit a2a9f87

Browse files
committed
📦 NEW: Added clwc_insert_loyalty_log_entry helper function
1 parent 517df78 commit a2a9f87

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

includes/clwc-helper-functions.php

+31
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,34 @@ function clwc_earning_points_money_spent() {
283283

284284
return apply_filters( 'clwc_earning_points_money_spent', $money_spent );
285285
}
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

Comments
 (0)