Skip to content

Commit dd91d42

Browse files
committed
📦 NEW: Added clwc_loyalty_log db table
1 parent 2ff4916 commit dd91d42

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

customer-loyalty-for-woocommerce.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @since 1.0.0
1111
*
1212
* @wordpress-plugin
13-
* Plugin Name: Customer Loyalty for WooCommerce®
13+
* Plugin Name: Loyalty & Rewards for WooCommerce®
1414
* Plugin URI: https://www.deviodigital.com/customer-loyalty-for-woocommerce
1515
* Description: Increase customer loyalty by rewarding your customers for their repeat purchase behavior.
1616
* Version: 1.3.1
@@ -32,6 +32,44 @@
3232
*/
3333
define( 'CUSTOMER_LOYALTY_VERSION', '1.3.1' );
3434

35+
/**
36+
* Create the CLWC Loyalty Log database table.
37+
*
38+
* This function creates a table for storing loyalty log entries in the database.
39+
* It includes fields for storing the customer ID, name, email, points, action details, and date.
40+
*
41+
* @package CLWC
42+
* @since 2.0.0
43+
*/
44+
function clwc_create_loyalty_log_table() {
45+
global $wpdb;
46+
47+
// Define table name with the WordPress table prefix.
48+
$table_name = $wpdb->prefix . 'clwc_loyalty_log';
49+
50+
// Set the database character set and collation for security.
51+
$charset_collate = $wpdb->get_charset_collate();
52+
53+
// SQL statement to create the table if it does not exist.
54+
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
55+
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
56+
user_id BIGINT(20) UNSIGNED NOT NULL,
57+
name VARCHAR(255) NOT NULL,
58+
email VARCHAR(255) NOT NULL,
59+
points INT(11) NOT NULL,
60+
details TEXT NOT NULL,
61+
date DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
62+
PRIMARY KEY (id),
63+
KEY user_id (user_id),
64+
KEY date (date)
65+
) $charset_collate;";
66+
67+
// Load the dbDelta function, which manages database upgrades and creation.
68+
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
69+
dbDelta( $sql );
70+
}
71+
register_activation_hook( __FILE__, 'clwc_create_loyalty_log_table' );
72+
3573
/**
3674
* The code that runs during plugin activation.
3775
* This action is documented in includes/class-clwc-activator.php

0 commit comments

Comments
 (0)