• Madern

    (@madern)


    There’s a bug in MailerLite for WooCommerce that triggers SQL errors and makes the settings page very slow when WordPress uses a custom table prefix.

    Environment:

    • WP with custom prefix bcksz_ (not wp_)
    • WooCommerce up to date
    • Query Monitor enabled

    Error from Query Monitor:

    Unknown column wp_wc_customer_lookup.customer_id in 'field list'

    Root cause:
    File: includes/models/WooMailerLiteCustomer.php
    Method: getAll($limit = 100)

    The SQL selects use hard-coded wp_ table names, e.g.:

    select("wp_wc_customer_lookup.customer_id, wp_wc_customer_lookup.email, max(wp_wc_order_stats.order_id) AS last_order_id, max(wp_wc_order_stats.date_created) AS last_order, count(DISTINCT wp_wc_order_stats.order_id) AS orders_count, sum(wp_wc_order_stats.total_sales) AS total_spent, ...")

    While the method already retrieves $prefix = db()->prefix; and uses {$prefix} in other parts of the query.

    Expected behavior:
    All WooCommerce table references must use the dynamic prefix ($wpdb->prefix / db()->prefix) instead of the hard-coded wp_.

    Proposed fix (idea):
    Replace wp_wc_customer_lookup / wp_wc_order_stats with variables built from the prefix:

    $prefix = db()->prefix; $tbl_customers = "{$prefix}wc_customer_lookup"; $tbl_orderstats = "{$prefix}wc_order_stats"; select("{$tbl_customers}.customer_id, {$tbl_customers}.email, max({$tbl_orderstats}.order_id) AS last_order_id, max({$tbl_orderstats}.date_created) AS last_order, count(DISTINCT {$tbl_orderstats}.order_id) AS orders_count, sum({$tbl_orderstats}.total_sales) AS total_spent, ...")

Viewing 1 replies (of 1 total)
  • Plugin Author MailerLite

    (@mailerlite)

    Hello, we have released a new update (3.0.8) to the plugin today, which must resolve this issue. Please make sure you have the plugin updated to the latest version.

    Regards.

Viewing 1 replies (of 1 total)

The topic ‘Custom DB Prefix’ is closed to new replies.