Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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;
    }

    Hi WooCommerce Development Team

    I have the very same problem. I came across the issue 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. The issue is also present in WC 9.3 Beta 1.

    According to the guidelines I will open a separate thread for my issue.

    • This reply was modified 5 months, 4 weeks ago by wprwb.

    I have solved this issue by just changing the CSS selector from

    .login h1 a

    to

    #login h1 a

Viewing 3 replies - 1 through 3 (of 3 total)