WPIntell

Source evidence

Customize serial numbers by specific pattern

Serial Numbers – Ultimate License Manager for Selling, Licensing & Securely Delivering Digital Content with WooCommerce · support · 2023-02-06T20:22:00+00:00

mixedsentiment
mediumseverity
0.85relevance
3replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

10 / 67 rows with source links

14.9% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

57 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
omrto resolved
This is more of a feature request. We generate our serial numbers using a specific method: SKU-Date(DDMMYY)-Order# (or we might change order# or a sequential number if need be). I know this is somewhat complicated, but it would be a nice feature to be able to build our own logic for the serial # generator. Hello @omrto , Thanks for reaching out. As you already know, currently the feature that you wanted is not available. We already have this feature request in our queue https://github.com/pluginever/wc-serial-numbers/issues/251 I’ll notify you when this update gets released. Hope you’re enjoying Serial Numbers for WooCommerce. Have a great day! Thank you for your reply @bappi . I’ll keep an eye out for this. @bappi , Here is a code that may or may not be useful to you. I got from ChatGPT. It is written to accommodate my unique needs, but I haven’t tried it out yet. Our company has been exploring the idea of developing our own custom ecommerce/production system in Laravel. If I come back around to this and try it out I will update this thread. // Get the current order items $order = wc_get_order( $order_id ); $order_items = $order->get_items(); // Loop through each order item foreach ( $order_items as $item_id => $item ) { // Get the product SKU and formatted date $product_sku = $item->get_product()->get_sku(); $date = date( "dmY" ); // Check the database for duplicate serial numbers $serial_number_check = check_for_duplicate_serial_number( $product_sku, $date, $order->get_order_number() ); // If there's no duplicate, generate the serial number if ( ! $serial_number_check ) { $serial_number = "{$product_sku}-{$date}-{$order->get_order_number()}"; } // If there is a duplicate, increment a letter at the end of the serial number else { $serial_number = "{$product_sku}-{$date}-{$order->get_order_number()}-{$serial_number_check}"; } // Save the serial number as a custom field for the product update_post_meta( $item_id, 'Serial#', $serial_number ); } // Function to check for duplicates in the database function check_for_duplicate_serial_number( $product_sku, $date, $order_number ) { global $wpdb; // Query the database for serial numbers that match the current product SKU, date, and order number $results = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = 'Serial#' AND meta_value LIKE %s", "{$product_sku}-{$date}-{$order_number network error }%") ); // If there are no duplicates, return false if ( count( $results ) === 0 ) { return false; } // If there are duplicates, increment a letter at the end of the serial number else { $letters = range('a', 'z'); $last_letter = end( $results )->meta_value[-1]; $current_index = array_search( $last_letter, $letters ); return $letters[$current_index + 1]; } }

Comments

3 shown
Mehedi Hasan 2023-02-07T07:07:00+00:00

Hello @omrto , Thanks for reaching out. As you already know, currently the feature that you wanted is not available. We already have this feature request in our queue https://github.com/pluginever/wc-serial-numbers/issues/251 I’ll notify you when this update gets released. Hope you’re enjoying Serial Numbers for WooCommerce. Have a great day!

omrto 2023-02-15T12:30:00+00:00

Thank you for your reply @bappi . I’ll keep an eye out for this.

omrto 2023-02-15T12:42:00+00:00

@bappi , Here is a code that may or may not be useful to you. I got from ChatGPT. It is written to accommodate my unique needs, but I haven’t tried it out yet. Our company has been exploring the idea of developing our own custom ecommerce/production system in Laravel. If I come back around to this and try it out I will update this thread. // Get the current order items $order = wc_get_order( $order_id ); $order_items = $order->get_items(); // Loop through each order item foreach ( $order_items as $item_id => $item ) { // Get the product SKU and formatted date $product_sku = $item->get_product()->get_sku(); $date = date( "dmY" ); // Check the database for duplicate serial numbers $serial_number_check = check_for_duplicate_serial_number( $product_sku, $date, $order->get_order_number() ); // If there's no duplicate, generate the serial number if ( ! $serial_number_check ) { $serial_number = "{$product_sku}-{$date}-{$order->get_order_number()}"; } // If there is a duplicate, increment a letter at the end of the serial number else { $serial_number = "{$product_sku}-{$date}-{$order->get_order_number()}-{$serial_number_check}"; } // Save the serial number as a custom field for the product update_post_meta( $item_id, 'Serial#', $serial_number ); } // Function to check for duplicates in the database function check_for_duplicate_serial_number( $product_sku, $date, $order_number ) { global $wpdb; // Query the database for serial numbers that match the current product SKU, date, and order number $results = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = 'Serial#' AND meta_value LIKE %s", "{$product_sku}-{$date}-{$order_number network error }%") ); // If there are no duplicates, return false if ( count( $results ) === 0 ) { return false; } // If there are duplicates, increment a letter at the end of the serial number else { $letters = range('a', 'z'); $last_letter = end( $results )->meta_value[-1]; $current_index = array_search( $last_letter, $letters ); return $letters[$current_index + 1]; } }