• Resolved wprwb

    (@wprwb)


    Hi WooCommerce Development Team

    I came across an issue with the WC coupon codes because a customer asked for the coupon which is programmatically generated when you subscribe to our newsletter. The programmatic creation has been working for years without any issues. Now, I cannot even correctly generate the coupon code in the WooCommerce Admin interface as the email restriction for the coupon code is not stored with the coupon. The issue in the Admin interface is also present in WC 9.3 Beta 1.

    Here is my System Status:

    WordPress Environment<br><br>WordPress address (URL): https://ichliebemeinzuhause.ch<br>Site address (URL): https://ichliebemeinzuhause.ch<br>WC Version: 9.2.3<br>Legacy REST API Package Version: Auf dieser Website ist das alte REST-API-Plugin nicht installiert.<br>Action Scheduler Version: ? 3.8.1<br>Log Directory Writable: ?<br>WP Version: 6.6.1<br>WP Multisite: –<br>WP Memory Limit: 1 GB<br>WP Debug Mode: –<br>WP Cron: ?<br>Language: de_DE_formal<br>External object cache: ? Server Environment<br><br>Server Info: Apache<br>PHP Version: 8.2.20<br>PHP Post Max Size: 256 MB<br>PHP Time Limit: 600<br>PHP Max Input Vars: 200000<br>cURL Version: 8.2.1<br>NSS/3.90<br><br>SUHOSIN Installed: –<br>MySQL Version: 10.6.18-MariaDB<br>Max Upload Size: 256 MB<br>Default Timezone is UTC: ?<br>fsockopen/cURL: ?<br>SoapClient: ?<br>DOMDocument: ?<br>GZip: ?<br>Multibyte String: ?<br>Remote Post: ?<br>Remote Get: ? Database<br><br>WC Database Version: 9.2.3<br>WC Database Prefix: 8f2s90q_<br>Datenbank-Gesamtgr?sse: 109.02MB<br>Datenbank-Datengr?sse: 92.11MB<br>Datenbank-Indexgr?sse: 16.91MB<br>8f2s90q_woocommerce_sessions: Daten: 1.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_woocommerce_api_keys: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB<br>8f2s90q_woocommerce_attribute_taxonomies: Daten: 0.00MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_woocommerce_downloadable_product_permissions: Daten: 0.00MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_woocommerce_order_items: Daten: 0.29MB + Index: 0.11MB + Engine MyISAM<br>8f2s90q_woocommerce_order_itemmeta: Daten: 1.44MB + Index: 0.95MB + Engine MyISAM<br>8f2s90q_woocommerce_tax_rates: Daten: 0.00MB + Index: 0.01MB + Engine MyISAM<br>8f2s90q_woocommerce_tax_rate_locations: Daten: 0.00MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_woocommerce_shipping_zones: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_woocommerce_shipping_zone_locations: Daten: 0.02MB + Index: 0.06MB + Engine InnoDB<br>8f2s90q_woocommerce_shipping_zone_methods: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_woocommerce_payment_tokens: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_woocommerce_payment_tokenmeta: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB<br>8f2s90q_woocommerce_log: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_actionscheduler_actions: Daten: 0.11MB + Index: 0.13MB + Engine InnoDB<br>8f2s90q_actionscheduler_claims: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_actionscheduler_groups: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_actionscheduler_logs: Daten: 0.08MB + Index: 0.03MB + Engine InnoDB<br>8f2s90q_commentmeta: Daten: 0.40MB + Index: 0.30MB + Engine MyISAM<br>8f2s90q_comments: Daten: 2.26MB + Index: 0.91MB + Engine MyISAM<br>8f2s90q_links: Daten: 0.00MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_newsletter: Daten: 0.05MB + Index: 0.03MB + Engine MyISAM<br>8f2s90q_newsletter_emails: Daten: 1.33MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_newsletter_logs: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_newsletter_sent: Daten: 0.33MB + Index: 0.62MB + Engine MyISAM<br>8f2s90q_newsletter_stats: Daten: 0.00MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_newsletter_user_logs: Daten: 0.16MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_newsletter_user_meta: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_odb_logs: Daten: 0.02MB + Index: 0.01MB + Engine MyISAM<br>8f2s90q_options: Daten: 28.25MB + Index: 1.82MB + Engine MyISAM<br>8f2s90q_postfinancecw_logs: Daten: 0.00MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_postfinancecw_transactions: Daten: 0.03MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_postmeta: Daten: 15.63MB + Index: 3.50MB + Engine MyISAM<br>8f2s90q_posts: Daten: 17.53MB + Index: 1.25MB + Engine MyISAM<br>8f2s90q_termmeta: Daten: 0.19MB + Index: 0.25MB + Engine InnoDB<br>8f2s90q_terms: Daten: 0.21MB + Index: 0.44MB + Engine MyISAM<br>8f2s90q_term_relationships: Daten: 0.67MB + Index: 1.30MB + Engine MyISAM<br>8f2s90q_term_taxonomy: Daten: 0.18MB + Index: 0.17MB + Engine MyISAM<br>8f2s90q_usermeta: Daten: 0.51MB + Index: 0.28MB + Engine MyISAM<br>8f2s90q_users: Daten: 0.03MB + Index: 0.04MB + Engine MyISAM<br>8f2s90q_wc_admin_notes: Daten: 0.06MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wc_admin_note_actions: Daten: 0.05MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wc_category_lookup: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wc_customer_lookup: Daten: 0.08MB + Index: 0.06MB + Engine InnoDB<br>8f2s90q_wc_download_log: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB<br>8f2s90q_wc_orders: Daten: 0.28MB + Index: 0.41MB + Engine InnoDB<br>8f2s90q_wc_orders_meta: Daten: 0.41MB + Index: 0.95MB + Engine InnoDB<br>8f2s90q_wc_order_addresses: Daten: 0.22MB + Index: 0.30MB + Engine InnoDB<br>8f2s90q_wc_order_coupon_lookup: Daten: 0.02MB + Index: 0.03MB + Engine InnoDB<br>8f2s90q_wc_order_operational_data: Daten: 0.16MB + Index: 0.11MB + Engine InnoDB<br>8f2s90q_wc_order_product_lookup: Daten: 0.20MB + Index: 0.28MB + Engine InnoDB<br>8f2s90q_wc_order_stats: Daten: 0.14MB + Index: 0.11MB + Engine InnoDB<br>8f2s90q_wc_order_tax_lookup: Daten: 0.06MB + Index: 0.03MB + Engine InnoDB<br>8f2s90q_wc_product_attributes_lookup: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wc_product_download_directories: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wc_product_meta_lookup: Daten: 0.17MB + Index: 0.39MB + Engine InnoDB<br>8f2s90q_wc_rate_limits: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wc_reserved_stock: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wc_tax_rate_classes: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wc_webhooks: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wfblockediplog: Daten: 0.05MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wfblocks7: Daten: 0.02MB + Index: 0.05MB + Engine InnoDB<br>8f2s90q_wfconfig: Daten: 1.30MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wfcrawlers: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wffilechanges: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wffilemods: Daten: 7.52MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wfhits: Daten: 1.02MB + Index: 1.11MB + Engine InnoDB<br>8f2s90q_wfhoover: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wfissues: Daten: 0.05MB + Index: 0.06MB + Engine InnoDB<br>8f2s90q_wfknownfilelist: Daten: 3.52MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wflivetraffichuman: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wflocs: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wflogins: Daten: 0.44MB + Index: 0.14MB + Engine InnoDB<br>8f2s90q_wfls_2fa_secrets: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_wfls_role_counts: Daten: 0.00MB + Index: 0.00MB + Engine MEMORY<br>8f2s90q_wfls_settings: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wfnotifications: Daten: 0.09MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wfpendingissues: Daten: 0.02MB + Index: 0.06MB + Engine InnoDB<br>8f2s90q_wfreversecache: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wfsecurityevents: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wfsnipcache: Daten: 0.02MB + Index: 0.05MB + Engine InnoDB<br>8f2s90q_wfstatus: Daten: 0.13MB + Index: 0.09MB + Engine InnoDB<br>8f2s90q_wftrafficrates: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_wfwaffailures: Daten: 0.02MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_woocommerce_postfinancecw_cc: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_woocommerce_postfinancecw_documents: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_woocommerce_postfinancecw_ecc: Daten: 0.16MB + Index: 0.00MB + Engine InnoDB<br>8f2s90q_woocommerce_postfinancecw_schema_version: Daten: 0.00MB + Index: 0.00MB + Engine MyISAM<br>8f2s90q_woocommerce_postfinancecw_storage: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB<br>8f2s90q_woocommerce_postfinancecw_transactions: Daten: 4.52MB + Index: 0.00MB + Engine InnoDB<br>postfinancecw_storage: Daten: 0.02MB + Index: 0.02MB + Engine InnoDB Post Type Counts<br><br>attachment: 6134<br>nav_menu_item: 3<br>page: 22<br>post: 664<br>product: 1319<br>revision: 3647<br>shop_coupon: 239<br>shop_order: 835<br>shop_order_refund: 2<br>user_request: 1 Security<br><br>Secure connection (HTTPS): ?<br>Hide errors from visitors: ? Active Plugins (10)<br><br>Classic Editor: von WordPress-Mitwirkende – 1.6.4<br>Classic Widgets: von WordPress-Mitwirkende – 0.3<br>Disable Embeds: von Pascal Birchler – 1.5.0<br>mame datatrans for WooCommerce: von mame software development hüttig – 2.7.0<br>Newsletter: von Stefano Lissa & Das Newsletter Team – 8.4.9<br>W3 Total Cache: von BoldGrid – 2.7.5<br>Print Invoice & Delivery Notes for WooCommerce: von Tyche Softwares – 5.1.0<br>WooCommerce Table Rate Shipping: von Bolder Elements – 4.3.11<br>WooCommerce: von Automattic – 9.2.3<br>Wordfence Security: von Wordfence – 7.11.7 Inactive Plugins (0) Dropin Plugins ()<br><br>advanced-cache.php: advanced-cache.php<br>db.php: db.php<br>object-cache.php: object-cache.php Settings<br><br>Legacy API Enabled: –<br>Force SSL: –<br>Currency: CHF (CHF)<br>Currency Position: left_space<br>Thousand Separator: ,<br>Decimal Separator: .<br>Number of Decimals: 2<br>Taxonomies: Product Types: external (external)<br>grouped (grouped)<br>simple (simple)<br>variable (variable)<br><br>Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)<br>exclude-from-search (exclude-from-search)<br>featured (featured)<br>outofstock (outofstock)<br>rated-1 (rated-1)<br>rated-2 (rated-2)<br>rated-3 (rated-3)<br>rated-4 (rated-4)<br>rated-5 (rated-5)<br><br>Connected to WooCommerce.com: –<br>Enforce Approved Product Download Directories: –<br>HPOS feature enabled: ?<br>Order datastore: Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore<br>HPOS data sync enabled: ? Logging<br><br>Enabled: ?<br>Handler: Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2<br>Retention period: 30 Tage<br>Level threshold: –<br>Log directory size: 325 B WC Pages<br><br>Shop-Basis: #19 - /shop/<br>Warenkorb: #20 - /warenkorb/ - Enth?lt den [woocommerce_cart]-Shortcode<br>Kasse: #21 - /kasse/ - Enth?lt den [woocommerce_checkout]-Shortcode<br>Mein Konto: #22 - /mein-konto/<br>Allgemeine Gesch?ftsbedingungen: #32 - /agb/ Theme<br><br>Name: ichliebemeinzuhause<br>Version: 6.4.0 / PROD<br>Author URL: https://webdesign-bolinger.ch<br>Child Theme: ? – Wenn Sie WooCommerce mit einem Theme<br>das Sie nicht selbst entwickelt haben<br>an eigene Bedürfnisse anpassen<br>dann empfehlen wir die Verwendung eines Child-Themes. Siehe Wie Sie ein Child-Theme erstellen (engl.)<br><br>WooCommerce Support: ? Templates<br><br>Overrides: ichliebemeinzuhause/woocommerce/cart/cart.php<br>ichliebemeinzuhause/woocommerce/content-product.php<br>ichliebemeinzuhause/woocommerce/emails/admin-cancelled-order.php<br>ichliebemeinzuhause/woocommerce/emails/admin-failed-order.php<br>ichliebemeinzuhause/woocommerce/emails/admin-new-order.php<br>ichliebemeinzuhause/woocommerce/emails/customer-completed-order.php<br>ichliebemeinzuhause/woocommerce/emails/customer-invoice.php<br>ichliebemeinzuhause/woocommerce/emails/customer-new-account.php<br>ichliebemeinzuhause/woocommerce/emails/customer-note.php<br>ichliebemeinzuhause/woocommerce/emails/customer-on-hold-order.php<br>ichliebemeinzuhause/woocommerce/emails/customer-processing-order.php<br>ichliebemeinzuhause/woocommerce/emails/customer-refunded-order.php<br>ichliebemeinzuhause/woocommerce/emails/customer-reset-password.php<br>ichliebemeinzuhause/woocommerce/emails/email-addresses.php<br>ichliebemeinzuhause/woocommerce/emails/email-customer-details.php<br>ichliebemeinzuhause/woocommerce/emails/email-footer.php<br>ichliebemeinzuhause/woocommerce/emails/email-header.php<br>ichliebemeinzuhause/woocommerce/emails/email-order-details.php<br>ichliebemeinzuhause/woocommerce/emails/email-order-items.php<br>ichliebemeinzuhause/woocommerce/global/quantity-input.php<br>ichliebemeinzuhause/woocommerce/loop/add-to-cart.php<br>ichliebemeinzuhause/woocommerce/single-product/add-to-cart/simple.php<br>ichliebemeinzuhause/woocommerce/single-product/product-image.php<br>ichliebemeinzuhause/woocommerce/content-product_cat.php Admin<br><br>Enabled Features: activity-panels<br>analytics<br>product-block-editor<br>coupons<br>core-profiler<br>customize-store<br>customer-effort-score-tracks<br>import-products-task<br>experimental-fashion-sample-products<br>shipping-smart-defaults<br>shipping-setting-tour<br>homescreen<br>marketing<br>mobile-app-banner<br>navigation<br>onboarding<br>onboarding-tasks<br>pattern-toolkit-full-composability<br>product-custom-fields<br>remote-inbox-notifications<br>remote-free-extensions<br>payment-gateway-suggestions<br>printful<br>shipping-label-banner<br>subscriptions<br>store-alerts<br>transient-notices<br>woo-mobile-welcome<br>wc-pay-promotion<br>wc-pay-welcome-page<br>launch-your-store<br><br>Disabled Features: experimental-blocks<br>minified-js<br>product-pre-publish-modal<br>settings<br>async-product-editor-category-field<br>product-editor-template-system<br><br>Daily Cron: ? Next scheduled: 2024-09-07 19:43:33 +02:00<br>Options: ?<br>Notes: 83<br>Onboarding: completed Action Scheduler<br><br>Abgeschlossen: 200<br>Oldest: 2024-08-08 02:25:02 +0200<br>Newest: 2024-09-07 15:49:41 +0200<br><br>Fehlgeschlagen: 11<br>Oldest: 2023-02-18 10:54:27 +0100<br>Newest: 2023-12-28 12:09:53 +0100<br><br>Ausstehend: 2<br>Oldest: 2024-09-08 09:55:03 +0200<br>Newest: 2024-09-08 15:49:41 +0200 Status report information<br><br>Generated at: 2024-09-07 17:14:23 +02:00<br>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @wprwb,

    Thank you for reaching out.

    which is programmatically generated when you subscribe to our newsletter

    I understand your coupons are programmatically generated, could you please clarify which plugin or function you’re using to have them generated, as this is not the normal behavior of the WooCommerce core plugin?

    ?The programmatic creation has been working for years without any issues.?

    Do you remember making any changes before the issue started, such as updating or installing plugin(s)?

    Thread Starter wprwb

    (@wprwb)

    Hi @ckadenge,

    Thanks for your reply.

    It is important to mention again that there seems to be a bug in the WooCommerce core plugin as coupon codes with an email restriction cannot be stored correctly when logged into the standard WordPress Admin and generated via the WooCommerce coupon code generator there.

    As my installation is up-to-date with WordPress (v6.6.1), WooCommerce (v9.2.3) and all other plugins I am using there have been a couple of updates in the past weeks and months.

    However, the WooCommerce coupon code generation function in my functions.php has not been changed for years. Here is the function:

    function ilmz_create_newsletter_coupon ( $newsletter_id, $newsletter_email ) {
    global $wpdb;
    $coupon_code = strtolower( 'TEST-'.$newsletter_id ); // Code
    $customer_email = strtolower(esc_html( $newsletter_email ));
    $newsletter_table_name = $wpdb->prefix . "newsletter";
    $existing_coupon = $wpdb->get_results( "SELECT wc_coupon, wc_coupon_expiry_date FROM " . $newsletter_table_name . " WHERE email= '" . $customer_email . "' AND wc_coupon LIKE 'test%'" );
    if ( empty($existing_coupon[0]->wc_coupon) ) {
    $amount = '10'; // Amount
    $minimum_amount = '100';
    $discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
    $usage_limit = '1';
    $usage_limit_per_user = '1';
    $expiry_date = date('Y-m-d', strtotime('+8 days'));
    $user_expiry_date = date('Y-m-d', strtotime('+7 days'));
    $coupon = array(
    'post_title' => $coupon_code,
    'post_content' => '',
    'post_status' => 'publish',
    'post_author' => 3,
    'post_type' => 'shop_coupon'
    );
    $new_coupon_id = wp_insert_post( $coupon );
    // Add meta
    update_post_meta( $new_coupon_id, 'discount_type', $discount_type );
    update_post_meta( $new_coupon_id, 'coupon_amount', $amount );
    update_post_meta( $new_coupon_id, 'minimum_amount', $minimum_amount );
    update_post_meta( $new_coupon_id, 'individual_use', 'no' );
    update_post_meta( $new_coupon_id, 'product_ids', '' );
    update_post_meta( $new_coupon_id, 'exclude_product_ids', '' );
    update_post_meta( $new_coupon_id, 'exclude_product_categories', '' );
    update_post_meta( $new_coupon_id, 'exclude_sale_items', 'no' );
    update_post_meta( $new_coupon_id, 'usage_limit', $usage_limit );
    update_post_meta( $new_coupon_id, 'usage_limit_per_user', $usage_limit_per_user );
    update_post_meta( $new_coupon_id, 'expiry_date', $expiry_date );
    update_post_meta( $new_coupon_id, 'apply_before_tax', 'no' );
    update_post_meta( $new_coupon_id, 'free_shipping', 'no' );
    update_post_meta( $new_coupon_id, 'customer_email', $customer_email );
    $ilmz_coupon = array(
    'coupon_code' => $coupon_code,
    'coupon_expiry_date' => $user_expiry_date
    );
    } else {
    $ilmz_coupon = array(
    'coupon_code' => $existing_coupon[0]->wc_coupon,
    'coupon_expiry_date' => $existing_coupon[0]->wc_coupon_expiry_date
    );
    }
    return $ilmz_coupon;
    }

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @wprwb

    For reference, this particular forum is meant for general support with the core functionality of WooCommerce itself. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.