first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
<?php
/**
* Get variation separator value.
*
* @return string The variation separator value.
*/
function get_variation_separator_value() {
// Get the value of "Enable variant settings" option.
$variant_settings_enabled = get_option('skuautoffxf_variation_settings');
// Get the value of "Variation Separator" option.
$variation_separator = get_option('skuautoffxf_variation_separator');
// Check if both options have values.
if (!empty($variant_settings_enabled) && !empty($variation_separator)) {
// If both values exist, return the value of "Variation Separator".
return $variation_separator;
} else {
// If at least one value is missing, return the default separator "-".
return '-';
}
}

View File

@@ -0,0 +1,194 @@
<?php
add_action( 'wp_ajax_load_posts_by_ajax', 'load_posts_by_ajax_callback' );
function load_posts_by_ajax_callback() {
$skuautoffxf_auto_number = get_option( 'skuautoffxf_auto_number' );
$skuautoffxf_auto_id = get_option( 'skuautoffxf_auto_ID' );
function shapeSpace_random_string($length) {
if ( empty( get_option( 'skuautoffxf_letters_and_numbers' ) ) ) {
$characters = '123456789';
} elseif ( 'ffxf_numbers' === get_option( 'skuautoffxf_letters_and_numbers' ) ) {
$characters = '123456789';
} elseif ( 'ffxf_letters' === get_option( 'skuautoffxf_letters_and_numbers' ) ) {
$characters = 'QWERTYUIOPASDFGHJKLZXCVBNM';
} elseif ( 'ffxf_landnum' === get_option( 'skuautoffxf_letters_and_numbers' ) ) {
$characters = '123456789QWERTYUIOPASDFGHJKLZXCVBNM123456789';
}
$strlength = strlen($characters);
$random = '';
for ($i = 0; $i < $length; $i++) {
$random .= $characters[rand(0, $strlength - 1)];
}
return $random.get_option( 'skuautoffxf_suffix' ).$_GET['number_dop'];
}
global $paged;
check_ajax_referer('load_more_posts', 'security');
$paged = empty($_GET['paged']) ? 1 : (int) $_GET['paged'];
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => '1',
'paged' => $paged,
);
$my_posts = new WP_Query( $args );
if ( $my_posts->have_posts() ) :
?>
<?php while ( $my_posts->have_posts() ) : $my_posts->the_post();
if ( 'yes' === $skuautoffxf_auto_id ) {
$skuautoffxf_id = get_the_id();
} else {
$skuautoffxf_id = '';
}
global $product;
$skuautoffxf_auto_variant = get_option( 'skuautoffxf_auto_variant' );
?>
<div>
<?php //echo get_post_meta( get_the_id(), '_sku', true ); ?>
<div>
<p class="title_product">
<?php
$varioant_message_1 = __( 'Variable product. Depending on the settings, SKU variations may be generated.', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_2 = __( 'SKU already exists and has not been recreated', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_3 = __( 'SKU was not detected but was recreated!', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_4 = __( 'SKU has been recreated', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_5 = __( 'Regular product', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_6 = __( 'SKU not detected', 'easy-woocommerce-auto-sku-generator' );
if ( $product->is_type( 'variable' ) && 'no' === $skuautoffxf_auto_variant ) {
echo '<span data-tooltip-right data-tooltip="' . $varioant_message_1 . '"><i class="dashicons dashicons-tickets-alt"></i></span> ';
}elseif( isset( $_GET['checked'] ) && $_GET['checked'] === '0' ){
if ( get_post_meta( get_the_ID(), '_sku', true ) ){
echo '<span data-tooltip-right data-tooltip="'. $varioant_message_2 . '"><i class="dashicons dashicons-migrate"></i></span>';
}else{
echo '<span data-tooltip-right data-tooltip="' . $varioant_message_3 . '"><i style="color: #FF5722;" class="dashicons dashicons-dismiss"></i></span>';
}
}elseif( isset( $_GET['checked'] ) && $_GET['checked'] === '1' ){
echo '<span data-tooltip-right data-tooltip="' . $varioant_message_4 . '"><i class="dashicons dashicons-admin-appearance"></i></span> ';
}else{
echo '<span data-tooltip-right data-tooltip="' . $varioant_message_5 . '"><i class="dashicons dashicons-paperclip"></i></span> ';
}
the_title();
?>
</p>
</div>
<div>
<span><?php echo __( 'New SKU:', 'easy-woocommerce-auto-sku-generator' ); ?> </span>
<span class="slr">
<?php
if ( 'ffxf_slug' === get_option( 'skuautoffxf_letters_and_numbers' ) ) {
if ( isset( $_GET['checked'] ) && $_GET['checked'] === '1' ){
$ffxf_slug = get_post_field( 'post_name', get_post() );
update_post_meta( get_the_ID(), '_sku', $ffxf_slug );
echo $ffxf_slug;
}
elseif ( isset( $_GET['checked'] ) && $_GET['checked'] === '0' ){
if ( get_post_meta( get_the_ID(), '_sku', true ) ){
echo get_post_meta( get_the_ID(), '_sku', true );
}else{
echo $varioant_message_6; // артикул не обнаружен
}
}
}else{
if ( isset( $_GET['checked'] ) && $_GET['checked'] === '1' ){
if ( '0' === $skuautoffxf_auto_number ) {
$skuautoffxf_auto_number = '';
}elseif ( empty( $skuautoffxf_auto_number ) ) {
$skuautoffxf_auto_number = rand(4, 7);
}
$result_generate = shapeSpace_random_string( $skuautoffxf_auto_number );
echo get_option( 'skuautoffxf_auto_prefix' ).$result_generate.$skuautoffxf_id;
update_post_meta( get_the_ID(), '_sku', get_option( 'skuautoffxf_auto_prefix' ).$result_generate.$skuautoffxf_id );
}
elseif ( isset( $_GET['checked'] ) && $_GET['checked'] === '0' ){
if ( '0' === $skuautoffxf_auto_number ) {
$skuautoffxf_auto_number = rand(4, 7);
}elseif ( empty( $skuautoffxf_auto_number ) ) {
$skuautoffxf_auto_number = rand(4, 7);
}
if ( get_post_meta( get_the_ID(), '_sku', true ) ){
echo get_post_meta( get_the_ID(), '_sku', true );
}else{
$result_generate = shapeSpace_random_string( $skuautoffxf_auto_number );
echo get_option( 'skuautoffxf_auto_prefix' ).$result_generate.$skuautoffxf_id;
update_post_meta( get_the_ID(), '_sku', get_option( 'skuautoffxf_auto_prefix' ).$result_generate.$skuautoffxf_id );
}
}
}
if ( $product->is_type( 'variable' ) && 'no' === $skuautoffxf_auto_variant ) {
// Include the file with the custom function.
require_once 'functions-plugin.php'; // Replace with the correct path to your functions.php file.
// Use the custom function to get the variation separator value.
$separator_value = get_variation_separator_value();
$parent_sku = get_post_meta( get_the_ID(), '_sku', true );
$children_ids = $product->get_children();
$count = 0;
// Loop through the variations Ids.
foreach ( $children_ids as $child_id ) {
$count++;
// Get an instance of the WC_Product_Variation object.
$variation = wc_get_product( $child_id );
// Set the prefix lenght based on variations count.
$prefix = sizeof( $children_ids ) < 100 ? sprintf( '%02d', $count) : sprintf( '%03d', $count);
// Geberate and set the sku.
try {
$variation->set_sku( $parent_sku . $separator_value . $prefix );
} catch ( WC_Data_Exception $e ){
}
// Save variation.
$variation->save();
}
}
?>
</span>
</div>
</div>
<?php endwhile; ?>
<?php
endif;
wp_die();
}

View File

@@ -0,0 +1,199 @@
<?php
add_action( 'wp_ajax_load_posts_by_ajax_category', 'load_posts_by_ajax_category_callback' );
function load_posts_by_ajax_category_callback() {
$skuautoffxf_auto_number = get_option( 'skuautoffxf_auto_number' );
$skuautoffxf_auto_id = get_option( 'skuautoffxf_auto_ID' );
$skuautoffxf_suffix = get_option( 'skuautoffxf_suffix' );
$skuautoffxf_number_dop = get_option( 'skuautoffxf_number_dop' );
function shapeSpace_random_string($length) {
if ( empty( get_option( 'skuautoffxf_letters_and_numbers' ) ) ) {
$characters = '123456789';
} elseif ( 'ffxf_numbers' === get_option( 'skuautoffxf_letters_and_numbers' ) ) {
$characters = '123456789';
} elseif ( 'ffxf_letters' === get_option( 'skuautoffxf_letters_and_numbers' ) ) {
$characters = 'QWERTYUIOPASDFGHJKLZXCVBNM';
} elseif ( 'ffxf_landnum' === get_option( 'skuautoffxf_letters_and_numbers' ) ) {
$characters = '123456789QWERTYUIOPASDFGHJKLZXCVBNM123456789';
}
$strlength = strlen($characters);
$random = '';
for ($i = 0; $i < $length; $i++) {
$random .= $characters[rand(0, $strlength - 1)];
}
return $random.get_option( 'skuautoffxf_suffix' ).$_GET['number_dop'];
}
global $paged;
check_ajax_referer('load_more_posts_category', 'security');
$paged = empty( $_GET['paged'] ) ? 1 : (int) $_GET['paged'];
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => '1',
'paged' => $paged,
'product_cat' => $_GET['select_cat'],
);
$my_posts = new WP_Query( $args );
if ( $my_posts->have_posts() ) :
?>
<?php while ( $my_posts->have_posts() ) : $my_posts->the_post();
if ( 'yes' === $skuautoffxf_auto_id ) {
$skuautoffxf_id = get_the_id();
} else {
$skuautoffxf_id = '';
}
global $product;
$skuautoffxf_auto_variant = get_option( 'skuautoffxf_auto_variant' );
?>
<div>
<?php //echo get_post_meta( get_the_id(), '_sku', true ); ?>
<div>
<p class="title_product">
<?php
$varioant_message_1 = __( 'Variable product. Depending on the settings, SKU variations may be generated.', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_2 = __( 'SKU already exists and has not been recreated', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_3 = __( 'SKU was not detected but was recreated!', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_4 = __( 'SKU has been recreated', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_5 = __( 'Regular product', 'easy-woocommerce-auto-sku-generator' );
$varioant_message_6 = __( 'SKU not detected', 'easy-woocommerce-auto-sku-generator' );
if ( $product->is_type( 'variable' ) && 'no' === $skuautoffxf_auto_variant ) {
echo '<span data-tooltip-right data-tooltip="' . $varioant_message_1 . '"><i class="dashicons dashicons-tickets-alt"></i></span> ';
}elseif( isset( $_GET['checked'] ) && $_GET['checked'] === '0' ){
if ( get_post_meta( get_the_ID(), '_sku', true ) ){
echo '<span data-tooltip-right data-tooltip="'. $varioant_message_2 . '"><i class="dashicons dashicons-migrate"></i></span>';
}else{
echo '<span data-tooltip-right data-tooltip="' . $varioant_message_3 . '"><i style="color: #FF5722;" class="dashicons dashicons-dismiss"></i></span>';
}
}elseif( isset( $_GET['checked'] ) && $_GET['checked'] === '1' ){
echo '<span data-tooltip-right data-tooltip="' . $varioant_message_4 . '"><i class="dashicons dashicons-admin-appearance"></i></span> ';
}else{
echo '<span data-tooltip-right data-tooltip="' . $varioant_message_5 . '"><i class="dashicons dashicons-paperclip"></i></span> ';
}
the_title();
?>
</p>
</div>
<div>
<span><?php echo __( 'New SKU:', 'easy-woocommerce-auto-sku-generator' ); ?> </span>
<span class="slr">
<?php
if ( 'ffxf_slug' === get_option( 'skuautoffxf_letters_and_numbers' ) ) {
if ( isset( $_GET['checked'] ) && $_GET['checked'] === '1' ){
$ffxf_slug = get_post_field( 'post_name', get_post() );
update_post_meta( get_the_ID(), '_sku', $ffxf_slug );
echo $ffxf_slug;
}
elseif ( isset( $_GET['checked'] ) && $_GET['checked'] === '0' ){
if ( get_post_meta( get_the_ID(), '_sku', true ) ){
echo get_post_meta( get_the_ID(), '_sku', true );
}else{
echo $varioant_message_6; // артикул не обнаружен
}
}
}else{
if ( isset( $_GET['checked'] ) && $_GET['checked'] === '1' ){
if ( '0' === $skuautoffxf_auto_number ) {
$skuautoffxf_auto_number = '';
}elseif ( empty( $skuautoffxf_auto_number ) ) {
$skuautoffxf_auto_number = rand(4, 7);
}
$result_generate = shapeSpace_random_string( $skuautoffxf_auto_number );
echo get_option( 'skuautoffxf_auto_prefix' ).$result_generate.$skuautoffxf_id;
update_post_meta( get_the_ID(), '_sku', get_option( 'skuautoffxf_auto_prefix' ).$result_generate.$skuautoffxf_id );
}
elseif ( isset( $_GET['checked'] ) && $_GET['checked'] === '0' ){
if ( '0' === $skuautoffxf_auto_number ) {
$skuautoffxf_auto_number = '';
}elseif ( empty( $skuautoffxf_auto_number ) ) {
$skuautoffxf_auto_number = rand(4, 7);
}
if ( get_post_meta( get_the_ID(), '_sku', true ) ){
echo get_post_meta( get_the_ID(), '_sku', true );
}else{
$result_generate = shapeSpace_random_string( $skuautoffxf_auto_number );
echo get_option( 'skuautoffxf_auto_prefix' ).$result_generate.$skuautoffxf_id;
update_post_meta( get_the_ID(), '_sku', get_option( 'skuautoffxf_auto_prefix' ).$result_generate.$skuautoffxf_id );
}
}
}
if ( $product->is_type( 'variable' ) && 'no' === $skuautoffxf_auto_variant ) {
// Include the file with the custom function.
require_once 'functions-plugin.php'; // Replace with the correct path to your functions.php file.
// Use the custom function to get the variation separator value.
$separator_value = get_variation_separator_value();
$parent_sku = get_post_meta( get_the_ID(), '_sku', true );
$children_ids = $product->get_children();
$count = 0;
// Loop through the variations Ids.
foreach ( $children_ids as $child_id ) {
$count++;
// Get an instance of the WC_Product_Variation object.
$variation = wc_get_product( $child_id );
// Set the prefix lenght based on variations count.
$prefix = sizeof( $children_ids ) < 100 ? sprintf( '%02d', $count) : sprintf( '%03d', $count);
// Geberate and set the sku.
try {
$variation->set_sku( $parent_sku . $separator_value . $prefix );
} catch ( WC_Data_Exception $e ){
}
// Save variation.
$variation->save();
}
}
?>
</span>
</div>
</div>
<?php endwhile; ?>
<?php
endif;
wp_die();
}

View File

@@ -0,0 +1,416 @@
<?php
/**
* Add settings to the specific section we created before
*/
add_filter('woocommerce_get_settings_products', 'skuautoffxf_all_settings', 10, 2);
/**
* All settings
*
* @param mixed $settings Setting SKU.
* @param mixed $current_section .
*
* @return array
*/
function skuautoffxf_all_settings($settings, $current_section)
{
wp_enqueue_script('ffxf_settings_script');
if ('skuautoffxf' === $current_section) {
$ffxf_settings_sku = array();
$ffxf_settings_sku[] = array(
'name' => __('General plugin settings', 'easy-woocommerce-auto-sku-generator'),
'type' => 'title',
'desc' => __('On this page you can configure sku', 'easy-woocommerce-auto-sku-generator'),
'id' => 'skuautoffxfid',
);
$ffxf_settings_sku[] = array(
'title' => __('Characters', 'easy-woocommerce-auto-sku-generator'),
'desc_tip' => __('SKU prefix and product ID are not counted', 'easy-woocommerce-auto-sku-generator'),
'id' => 'skuautoffxf_auto_number',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
'default' => '5',
'class' => 'manage_stock_field',
'css' => 'display:block; width:50px;',
'desc' => __('Specify the number of characters in SKU', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Prefix SKU', 'easy-woocommerce-auto-sku-generator'),
'type' => 'text',
'default' => '',
'placeholder' => 'For example BN_',
'desc_tip' => __('Characters in the prefix are not assigned to the total number of characters (field above)', 'easy-woocommerce-auto-sku-generator'),
'id' => 'skuautoffxf_auto_prefix',
'css' => 'width:100%;display:block',
'desc' => __('Enter any prefix that will be displayed at the beginning of the SKU. <br>For example <span class="skuautoffxf_separator">BN_</span>893267', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Select SKU format', 'easy-woocommerce-auto-sku-generator'),
'id' => 'skuautoffxf_letters_and_numbers',
'type' => 'radio',
'default' => 'ffxf_numbers',
'css' => 'color:red',
'options' => array(
'ffxf_numbers' => __('Only numbers, for example - 893267', 'easy-woocommerce-auto-sku-generator'),
'ffxf_letters' => __('Only letters, for example - KSZHGD', 'easy-woocommerce-auto-sku-generator'),
'ffxf_landnum' => __('Letters and numbers, for example - 7SZ4G2', 'easy-woocommerce-auto-sku-generator'),
'ffxf_slug' => __('Use product slug, for example - your-product', 'easy-woocommerce-auto-sku-generator'),
),
);
$ffxf_settings_sku[] = array(
'name' => __('Add product ID', 'easy-woocommerce-auto-sku-generator'),
'type' => 'checkbox',
'id' => 'skuautoffxf_auto_ID',
'css' => 'min-width:300px;display:block',
'desc' => __('If checked, product ID will be added to SKU', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Take previous product', 'easy-woocommerce-auto-sku-generator'),
'type' => 'checkbox',
'id' => 'skuautoffxf_previous',
'css' => 'min-width:300px;display:block',
'desc' => __('Take into account the previous product', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Duplicate SKUs', 'easy-woocommerce-auto-sku-generator'),
'type' => 'checkbox',
'id' => 'skuautoffxf_duplicate_sku',
'css' => 'min-width:300px;display:block',
'desc' => __('Allow identical SKUs. If enabled, some SKUs can be identical', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('SKU suffix', 'easy-woocommerce-auto-sku-generator'),
'type' => 'text',
'id' => 'skuautoffxf_suffix',
'css' => 'min-width:300px;display:block',
'placeholder' => 'For example "_SUF_"',
'desc_tip' => __('The suffix is set at the end of the SKU and can have different characters. We recommend using the suffix in combination with the "Additional number" option e.g. suffix "_" and additional number "001" then your SKU will have this format BN_893267<em>_001</em>.', 'easy-woocommerce-auto-sku-generator'),
'desc' => __('Enter any suffix that will appear at the end of the SKU. <br>For example BN_893267<span class="skuautoffxf_separator">_SUF_</span>', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Additional number', 'easy-woocommerce-auto-sku-generator'),
'type' => 'number',
'id' => 'skuautoffxf_number_dop',
'css' => 'min-width:300px;display:block',
'placeholder' => 'For example "001"',
'desc_tip' => __('For example, you can set this field to 001 and then +1 will be added at the end of the SKU when the SKU is generated. In this way you can generate SKUs in order 001, 002, 003. We recommend using the suffix in combination with the "SKU suffix" option', 'easy-woocommerce-auto-sku-generator'),
'desc' => __('This number is applied at the end of the SKU for the mass generator and adds +1 at each step.<br>For example BN_893267_SUF_<span class="skuautoffxf_separator">001</span>', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Format "Additional number"', 'easy-woocommerce-auto-sku-generator'),
'id' => 'skuautoffxf_format_an',
'type' => 'select',
'default' => 'ffxf_format_an',
'options' => array(
'ffxf_format_an' => __('For example: 008 → 009 → 0010 → 0011', 'easy-woocommerce-auto-sku-generator'),
'ffxf_format_an_up' => __('For example: 008 → 009 → 010 → 011', 'easy-woocommerce-auto-sku-generator'),
),
'desc_tip' => __('This option is experimental, and specifying "0" at the beginning may lead to incorrect results. This functionality will be improved over time', 'easy-woocommerce-auto-sku-generator'),
'desc' => __('In the previous field, you selected a value that starts with "0" so you can choose the generation format', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Enable variant settings', 'easy-woocommerce-auto-sku-generator'),
'type' => 'checkbox',
'id' => 'skuautoffxf_variation_settings',
'css' => 'min-width:300px;display:block',
'desc' => __('If enabled, you can fine-tune the generation of variant SKU more precisely', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Variation Separator', 'easy-woocommerce-auto-sku-generator'),
'type' => 'text',
'default' => '',
'placeholder' => 'For example "-"',
'id' => 'skuautoffxf_variation_separator',
'css' => 'width:100%;display:block',
'desc_tip' => __('This setting is responsible for the separator between the main SKU and the variation number.', 'easy-woocommerce-auto-sku-generator'),
'desc' => __('You can use the characters "/", "\", "|", "-", "--", ".", "&", "#", "$", "@" or another prefix "_var_". <br>For example BN_893267<span class="skuautoffxf_separator">--</span>01, BN_893267<span class="skuautoffxf_separator">--</span>02<br>Another example BN_893267<span class="skuautoffxf_separator">_var_</span>01, BN_893267<span class="skuautoffxf_separator">_var_</span>02', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array(
'name' => __('Variable product', 'easy-woocommerce-auto-sku-generator'),
'type' => 'checkbox',
'id' => 'skuautoffxf_auto_variant',
'css' => 'min-width:300px;display:block',
'desc' => __('Turn off generation of variable product', 'easy-woocommerce-auto-sku-generator'),
);
$ffxf_settings_sku[] = array('type' => 'sectionend', 'id' => 'skuautoffxf');
return $ffxf_settings_sku;
} else {
return $settings;
}
}
add_action('admin_print_footer_scripts', 'ffxf_action_javascript', 998);
function ffxf_action_javascript()
{
?>
<script type="text/javascript">
function incrementWithLeadingZeros(number) {
// Convert the number to a string
number = number.toString();
// Remove leading zeros (if any)
var leadingZeros = number.match(/^0+/);
if (leadingZeros) {
leadingZeros = leadingZeros[0];
number = number.substring(leadingZeros.length);
}
// Convert the string back to a number
var parsedNumber = parseInt(number);
// Get the format option from WooCommerce
var formatOption = '<?php echo get_option("skuautoffxf_format_an"); ?>';
// Check if the number is an integer or with a decimal point
if (!isNaN(parsedNumber)) {
// Determine the increment based on the format option
var incrementValue = 1;
// Increment the number without removing leading zeros
parsedNumber += incrementValue;
// Convert the number back to a string with leading zeros
var formattedNumber = parsedNumber.toString();
if (formatOption === 'ffxf_format_an_up') {
if (leadingZeros) {
while (formattedNumber.length < number.length) {
formattedNumber = '0' + formattedNumber;
}
formattedNumber = leadingZeros + formattedNumber;
if (formattedNumber.endsWith('010') || formattedNumber.endsWith('100')) {
formattedNumber = formattedNumber.substring(1);
}
} else {
formattedNumber = formattedNumber.padStart(number.length, '0');
}
} else {
formattedNumber = formattedNumber.padStart(number.length, '0');
}
if (leadingZeros && formatOption !== 'ffxf_format_an_up') {
formattedNumber = leadingZeros + formattedNumber;
}
return formattedNumber;
}
// If the number is not recognized, return the original string without changes
return number;
}
// Getting the value of the skuautoffxf_number_dop option
var number_dop = '<?php echo get_option( 'skuautoffxf_number_dop' ); ?>';
var paged = 1;
var procent = <?php echo wp_count_posts('product')->publish; ?>;
var procent_total = <?php echo wp_count_posts('product')->publish; ?>;
jQuery(function ($) {
$.function_product_update = function () {
// If it is the first startup, leave the value
if(paged === 1){
number_dop = '<?php echo get_option( 'skuautoffxf_number_dop' ); ?>';
}else if (number_dop !== '') {
number_dop = incrementWithLeadingZeros(number_dop);
} else {
// Otherwise, assign an empty string
number_dop = '';
}
var data = {
'action': 'load_posts_by_ajax',
'paged': paged,
'number_dop': number_dop,
'security': '<?php echo wp_create_nonce("load_more_posts"); ?>',
'class': 'load_more_posts',
'checked': $('#check_generate').prop('checked') ? 1 : 0,
};
$.get(ajaxurl, data, function (response) {
if (response != '') {
$('.modal_generate .my-posts').append(response);
paged++;
procent--;
var edenica = procent_total;
var celoe = procent;
var proc = 100;
var gotovo = proc - (celoe * proc / edenica);
$('.modal_generate .progress-pie-chart').attr('data-percent', gotovo.toFixed());
var $ppc = $('.modal_generate .progress-pie-chart'),
percent = gotovo.toFixed(),
deg = (360 * percent++) / 100;
if (percent > 50) {
$ppc.addClass('gt-50');
}
if (percent >= 100) {
percent = 100;
deg = 360;
}
if (procent === 0) {
percent = 100;
deg = 360;
}
$('.modal_generate .ppc-progress-fill').css('transform', 'rotate(' + deg + 'deg)');
$('.modal_generate .ppc-percents span').html(percent + '%');
$('.modal_generate label#check_gen').hide();
$('.modal_generate .ps').text('<?php echo __("Products left:", "easy-woocommerce-auto-sku-generator"); ?> ' + procent);
$.function_product_update();
} else {
$('.modal_generate .generate_button').hide();
$('.modal_generate .ps').text('<?php echo __("Product processing completed!", "easy-woocommerce-auto-sku-generator"); ?>');
$('.modal_generate #text_generate_modal').fadeOut().fadeIn().text('<?php echo __("Thanks for waiting! If the process did not work correctly, please refer to the user support forum.", "easy-woocommerce-auto-sku-generator"); ?>');
}
});
};
$('body').on('click', '.generate_button', function () {
$.function_product_update();
$('.modal_generate .progress-pie-chart').fadeIn();
$('.modal_generate .generate_button').fadeOut();
$('.modal_generate #text_generate_modal').fadeOut().fadeIn().text(' <?php echo __("At the moment, the process of generating all articles is in progress. The process will take some time, please wait until the end!", "easy-woocommerce-auto-sku-generator"); ?>');
});
});
</script>
<?php
}
add_action('admin_print_footer_scripts', 'action_javascript_category', 999);
function action_javascript_category()
{
?>
<script type="text/javascript">
var paged = 1;
//var procent = <?php //echo wp_count_posts('product')->publish; ?>;
jQuery(function ($) {
$.function_product_update_category = function () {
// Если значение опции не пустое, выполнить прибавление с ведущими нулями
if (number_dop !== '') {
number_dop = incrementWithLeadingZeros(number_dop);
} else {
// В противном случае, присвоить пустую строку
number_dop = '';
}
var data = {
'action': 'load_posts_by_ajax_category',
'paged': paged,
'number_dop': number_dop,
'security': '<?php echo wp_create_nonce("load_more_posts_category"); ?>',
'class': 'load_more_posts_category',
'checked': $('.modal_generate_category #check_generate_category').prop('checked') ? 1 : 0,
'select_cat': $('.modal_generate_category #product_cat').val(),
};
$.get(ajaxurl, data, function (response) {
if (response != '') {
var select_cat = jQuery('.modal_generate_category .ps').text();
var num_category = parseInt(select_cat.replace(/\D+/g, ""));
var procent = num_category;
var procent_total = parseInt(jQuery('#product_cat option:selected').text().replace(/\D+/g, ""));
$('.modal_generate_category .my-posts').append(response);
paged++;
procent--;
var edenica = num_category;
var celoe = procent_total;
var proc = 100;
var gotovo = proc - (edenica * proc / celoe);
$('.modal_generate_category .progress-pie-chart').attr('data-percent', gotovo.toFixed());
var $ppc = $('.modal_generate_category .progress-pie-chart'),
percent = gotovo.toFixed(),
deg = (360 * percent++) / 100;
if (percent > 50) {
$ppc.addClass('gt-50');
}
if (percent >= 100) {
percent = 100;
deg = 360;
}
if (procent === 0) {
percent = 100;
deg = 360;
}
$('.modal_generate_category .ppc-progress-fill').css('transform', 'rotate(' + deg + 'deg)');
$('.modal_generate_category .ppc-percents span').html(percent + '%');
$('.modal_generate_category label#check_gen').hide();
$('.modal_generate_category .ps').text('<?php echo __("Products left:", "easy-woocommerce-auto-sku-generator"); ?> ' + procent);
$.function_product_update_category();
} else {
$('.modal_generate_category .generate_button_category').hide();
$('.modal_generate_category .ps').text('<?php echo __("Category processing completed!", "easy-woocommerce-auto-sku-generator"); ?>');
$('.modal_generate_category #text_generate_modal').fadeOut().fadeIn().text('<?php echo __("Thanks for waiting! If the process did not work correctly, please refer to the user support forum.", "easy-woocommerce-auto-sku-generator"); ?>');
}
});
};
$('body').on('click', '.generate_button_category', function () {
$.function_product_update_category();
$('.modal_generate_category .progress-pie-chart').fadeIn();
$('.modal_generate_category .generate_button_category').fadeOut();
$('select#product_cat').fadeOut();
$('.modal_generate_category #text_generate_modal').fadeOut().fadeIn().text(' <?php echo __("At the moment, the process of generating all articles is in progress. The process will take some time, please wait until the end!", "easy-woocommerce-auto-sku-generator"); ?>');
});
});
</script>
<?php
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Notifications to the user about the plugin revocation
**/
add_action( 'admin_notices', 'ffxf_plugin_notice_rate' );
function ffxf_plugin_notice_rate() {
if ( current_user_can( 'manage_options' ) ) {
$glideffxf_data_install = get_option( 'glideffxf_data_install' );
if ( $glideffxf_data_install === null || $glideffxf_data_install === false || strtotime( date( "Y-m-d" ) ) >= strtotime( $glideffxf_data_install ) ) {
wp_enqueue_script( 'ffxf-rate-sku' );
?>
<div id="ffxf_rate_sku" class="notice notice-info is-dismissible">
<p><img src="https://ps.w.org/easy-woocommerce-auto-sku-generator/assets/icon-128x128.png" alt="" style="float: left; width: 96px; margin-right: 14px; border-radius: 4px;">
<?php echo __( 'Hello!', 'easy-woocommerce-auto-sku-generator' ); ?><br>
<?php echo __( 'We are very pleased that you are using the <b>Easy Auto SKU Generator for WooCommerce</b> plugin within a few days.', 'easy-woocommerce-auto-sku-generator' ); ?>
<br>
<?php echo __( 'Please rate plugin. It will help us a lot.', 'easy-woocommerce-auto-sku-generator' ); ?>
</p>
<p>
<a id="i_have_already_by_ajax_callback" class="button button-secondary"
href="#"><?php echo __( 'Don\'t show again!', 'easy-woocommerce-auto-sku-generator' ); ?>
<span style="font-size: 16px; position: relative; bottom: -5px;"
class="dashicons dashicons-smiley"></span></a>
<a id="remind_me_later_by_ajax_callback" class="button button-secondary"
href="#"><?php echo __( 'Remind me later', 'easy-woocommerce-auto-sku-generator' ); ?> <span
style="font-size: 16px; position: relative; bottom: -5px;"
class="dashicons dashicons-backup"></span></a>
<a target="_blank" id="leave_feedback" class="button button-primary"
href="https://wordpress.org/support/plugin/easy-woocommerce-auto-sku-generator/reviews/#new-post"><?php echo __( 'Leave feedback', 'easy-woocommerce-auto-sku-generator' ); ?>
<span style="font-size: 16px; position: relative; bottom: -5px;"
class="dashicons dashicons-format-status"></span></a>
</p>
</div>
<?php
}
}
}
add_action( 'wp_ajax_i_have', 'i_have_already_by_ajax_callback' );
function i_have_already_by_ajax_callback() {
if ( current_user_can( 'manage_options' ) ) {
update_option( 'glideffxf_data_install', date( 'Y-m-d', strtotime( '+4 years' ) ) );
wp_die();
}
}
add_action( 'wp_ajax_remind_me_later', 'remind_me_later_by_ajax_callback' );
function remind_me_later_by_ajax_callback() {
if ( current_user_can( 'manage_options' ) ) {
update_option( 'glideffxf_data_install', date( 'Y-m-d', strtotime( '+1 days' ) ) );
wp_die();
}
}
add_action( 'wp_ajax_leave_feedback', 'leave_feedback_by_ajax_callback' );
function leave_feedback_by_ajax_callback() {
if ( current_user_can( 'manage_options' ) ) {
update_option( 'glideffxf_data_install', date( 'Y-m-d', strtotime( '+5 years' ) ) );
wp_die();
}
}

View File

@@ -0,0 +1,234 @@
<?php
/**
* Opening a wrapper hook for a website bar and information and bulk generator
*/
function skuautoffxf_action_open() {
if ( isset( $_GET['section'] ) && $_GET['section'] === 'skuautoffxf' ){
?>
<?php add_thickbox(); ?>
<h1><?php echo __( 'Easy Auto SKU Generator for WooCommerce', 'easy-woocommerce-auto-sku-generator' ); ?></h1>
<div class="wrapper_setting_ffxf">
<div class="block_left">
<div id="postbox-container-2" class="postbox-container postbox">
<div class="meta-box-sortables">
<div id="woocommerce_awooc_call_to_rate" class="postbox__ffxf">
<div class="inside">
<span class="dashicons dashicons-admin-generic my_generic_two"></span>
<h2><span><?php echo __( 'Bulk generation SKU', 'easy-woocommerce-auto-sku-generator' ); ?></span></h2>
<p><?php echo __( 'Some features are not yet available and are under development. Please wait for the update.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<hr>
<div class="mass_generate">
<div><i class="woocommerce-help-tip" data-tip="<?php echo __( 'This function will save the SKU of the loy of all goods, but first set the settings and save the page. You can also turn off the SKU generation on those products that already have SKU', 'easy-woocommerce-auto-sku-generator' ); ?>"></i> <?php echo __( 'Bulk generate SKU for all products', 'easy-woocommerce-auto-sku-generator' ); ?></div>
<div><a id="generate_mass_sku" class="button-primary open"><?php echo __( 'Generate all SKU', 'easy-woocommerce-auto-sku-generator' ); ?></a></div>
</div>
<hr>
<div class="mass_generate">
<div><i class="woocommerce-help-tip" data-tip="<?php echo __( 'You can create SKUs in separate categories. To do this, first save the settings, and then run the generator in the desired category. Thus, you can create more diverse SKUs, for example, with different prefixes.', 'easy-woocommerce-auto-sku-generator' ); ?>"></i> <?php echo __( 'Bulk generate SKU by Category', 'easy-woocommerce-auto-sku-generator' ); ?></div>
<div><a id="generate_mass_sku_category" name="save" class="button-primary woocommerce-save-button open_category"><?php echo __( 'Generate by Category', 'easy-woocommerce-auto-sku-generator' ); ?></a></div>
</div>
<hr>
<div class="mass_generate">
<div><i class="woocommerce-help-tip" data-tip="<?php echo __( 'The function is under development and will most likely be available in paid versions.', 'easy-woocommerce-auto-sku-generator' ); ?>"></i> <?php echo __( 'Bulk generate SKU by Attributes', 'easy-woocommerce-auto-sku-generator' ); ?></div>
<div><button name="save" class="button-primary woocommerce-save-button disabled" disabled><?php echo __( 'Generate by Attributes', 'easy-woocommerce-auto-sku-generator' ); ?></button></div>
</div>
<hr>
<div class="mass_generate">
<div><i class="woocommerce-help-tip" data-tip="<?php echo __( 'The function is under development and will most likely be available in paid versions.', 'easy-woocommerce-auto-sku-generator' ); ?>"></i> <?php echo __( 'Bulk generate SKU by product tags', 'easy-woocommerce-auto-sku-generator' ); ?></div>
<div><button name="save" class="button-primary woocommerce-save-button disabled" disabled><?php echo __( 'Generate by tags', 'easy-woocommerce-auto-sku-generator' ); ?></button></div>
</div>
</div>
</div>
</div>
</div>
<div id="postbox-container-4" class="postbox-container postbox">
<div class="meta-box-sortables">
<div id="woocommerce_awooc_call_to_rate" class="postbox__ffxf">
<div class="inside">
<span class="dashicons dashicons-chart-pie"></span>
<h2><span><?php echo __( 'Recommended Plugins', 'easy-woocommerce-auto-sku-generator' ); ?></span></h2>
<p><span><?php echo __( 'Let me recommend some plugins that can provide the greatest conversion for your store.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<hr>
<div class="recomendated_plugin_block">
<div><img src="https://ps.w.org/carousel-upsells-and-related-product-for-woocommerce/assets/icon-256x256.png" alt=""></div>
<div>
<a href="/wp-admin/plugin-install.php?tab=plugin-information&amp;plugin=carousel-upsells-and-related-product-for-woocommerce&amp;TB_iframe=true&amp;width=772&amp;height=468" class="thickbox open-plugin-details-ffxf-modal" aria-label="Carousel Upsells and Related Product for Woocommerce" data-title="Carousel Upsells and Related Product for Woocommerce"><h4><?php echo __( 'Carousel Upsells and Related Product for Woocommerce.', 'easy-woocommerce-auto-sku-generator' ); ?></h4></a>
</div>
</div>
<hr>
<div class="recomendated_plugin_block">
<div><img src="https://ps.w.org/art-woocommerce-order-one-click/assets/icon.svg" alt=""></div>
<div>
<a href="/wp-admin/plugin-install.php?tab=plugin-information&amp;plugin=art-woocommerce-order-one-click&amp;TB_iframe=true&amp;width=772&amp;height=468" class="thickbox open-plugin-details-ffxf-modal" aria-label="Art WooCommerce Order One Click" data-title="Art WooCommerce Order One Click"><h4><?php echo __( 'Art WooCommerce Order One Click', 'easy-woocommerce-auto-sku-generator' ); ?></h4></a>
</div>
</div>
<hr>
<div class="recomendated_plugin_block">
<div><img src="https://ps.w.org/luckywp-scripts-control/assets/icon-128x128.png" alt=""></div>
<div>
<a href="/wp-admin/plugin-install.php?tab=plugin-information&amp;plugin=luckywp-scripts-control&amp;TB_iframe=true&amp;width=600&amp;height=550" class="thickbox open-plugin-details-ffxf-modal" aria-label="LuckyWP Scripts Control" data-title="LuckyWP Scripts Control"><h4><?php echo __( 'LuckyWP Scripts Control', 'easy-woocommerce-auto-sku-generator' ); ?></h4></a>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="postbox-container-1" class="postbox-container postbox">
<div class="meta-box-sortables">
<div id="woocommerce_awooc_call_to_rate" class="postbox__ffxf">
<div class="inside inside_icons">
<span class="dashicons dashicons-businessperson"></span>
<h2><span><?php echo __( 'Message from the author', 'easy-woocommerce-auto-sku-generator' ); ?></span></h2>
<p><?php echo __( 'New function “Bulk generate SKU for all products” has been added. You can mass update the SKU now, but before save the general settings.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<p><?php echo __( 'We will refine the function of mass generation and add new functions. We are waiting your advice on the', 'easy-woocommerce-auto-sku-generator' ); ?> <a href="https://wordpress.org/support/plugin/easy-woocommerce-auto-sku-generator/" target="_blank"><?php echo __( 'support forum', 'easy-woocommerce-auto-sku-generator' ); ?></a>.</p>
<p><?php echo __( 'Some functions will be available only in the professional version of the plugin. The most active installers and testers are waiting gifts pro version the plugin "Easy Auto SKU Generator for WooCommerce".', 'easy-woocommerce-auto-sku-generator' ); ?></p>
</div>
</div>
</div>
</div>
<div id="postbox-container-3" class="postbox-container postbox">
<div class="meta-box-sortables">
<div id="woocommerce_awooc_call_to_rate" class="postbox__ffxf">
<div class="inside">
<span class="dashicons dashicons-buddicons-topics"></span>
<h2><span><?php echo __( 'Donate to development', 'easy-woocommerce-auto-sku-generator' ); ?></span></h2>
<p><?php echo __( 'You can make a donation to make the plugin Easy Auto SKU Generator for WooCommerce even better!', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<p><?php echo __( 'You can contribute any amount for improving the plugin. Paid support is also available by subscribing to the Boosty blog.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<p class="center"><a id="donate" target="_blank" href="https://boosty.to/dan-zakirov/donate"><?php echo __( 'Donate to plugin development', 'easy-woocommerce-auto-sku-generator' ); ?></a> </p>
<p class="center"><a href="https://wordpress.org/support/plugin/easy-woocommerce-auto-sku-generator/reviews/" target="_blank"><?php echo __( 'Leave feedback on the official repository', 'easy-woocommerce-auto-sku-generator' ); ?></a></p>
</div>
</div>
</div>
</div>
<div id="postbox-container-5" class="postbox-container postbox">
<div class="meta-box-sortables">
<div class="postbox__ffxf">
<div class="inside">
<span class="dashicons dashicons-editor-unlink"></span>
<h2><span><?php echo __( 'Elevate Your Experience: Paid User Support and Subscription', 'easy-woocommerce-auto-sku-generator' ); ?></span></h2>
<p><?php echo __( 'Due to the lack of available time for free plugin support, a decision has been made to introduce paid user support. Throughout my years of experience in web development, I have accumulated enough expertise to assist other users with various inquiries.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<p><?php echo __( 'By subscribing to Dan Zakirov\'s blog on Boosty at <a href="https://boosty.to/dan-zakirov" target="_blank">https://boosty.to/dan-zakirov</a>, you\'ll not only gain access to paid support for the "Easy Auto SKU Generator for WooCommerce" plugin but also a comprehensive range of consultations related to WooCommerce. Over the years, I have amassed numerous ready-made solutions, a variety of other plugins, and WordPress templates covering different aspects of WooCommerce and beyond.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<p><?php echo __( 'Additionally, the blog will feature interesting articles and reviews on different plugins. If you provide an original idea, I will strive to develop an entire plugin, and together we can work on advancing specific directions.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<p><a class="air-join" href="https://boosty.to/dan-zakirov" target="_blank"><?php echo __( 'Join Pro User Community', 'easy-woocommerce-auto-sku-generator' ); ?></a></p>
</div>
</div>
</div>
</div>
</div>
<div><span class="dashicons dashicons-rest-api my_generic"></span>
<?php
}
}
add_action( 'woocommerce_settings_products', 'skuautoffxf_action_open' );
function skuautoffxf_modal_setting() {
if ( isset( $_GET['section'] ) && $_GET['section'] === 'skuautoffxf' ) { ?>
<!-- MODAL - Bulk generate SKU for all products -->
<div class="ffxf-modal-frame modal_generate">
<div class="ffxf-modal">
<div class="ffxf-modal-inset">
<div class="button close"><i class="dashicons dashicons-no-alt"></i></div>
<div class="ffxf-modal-body">
<h2><?php echo __( 'Bulk generate SKU for all products', 'easy-woocommerce-auto-sku-generator' ); ?></h2>
<p id="text_generate_modal"><?php echo __( 'If you saved the general settings, you can continue. Based on the saved settings, the next step will be performed. After clicking on the button “Create SKU for all products”, the creation process for all goods will be launched in your online store, and this will take some time.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<button class="generate_button"><?php echo __( 'Create SKU for all products', 'easy-woocommerce-auto-sku-generator' ); ?></button>
<label for="check_generate" id="check_gen">
<input id="check_generate" name="check_generate" type="checkbox" class="checkbox check_generate_on"> <?php echo __( 'Re-create existing SKUs?', 'easy-woocommerce-auto-sku-generator' ); ?>
</label>
<div class="progress-pie-chart" data-percent="1" style="display:none">
<div class="ppc-progress">
<div class="ppc-progress-fill"></div>
</div>
<div class="ppc-percents">
<div class="pcc-percents-wrapper">
<span id="chet">%</span>
</div>
</div>
</div>
<p class="ps"><?php echo __( 'There are', 'easy-woocommerce-auto-sku-generator' ); ?> <?php echo wp_count_posts('product')->publish; ?> <?php echo __( 'products in your store.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<div class="over">
<div class="my-posts"></div>
</div>
</div>
</div>
</div>
</div>
<!-- MODAL - Bulk generate SKU by Category -->
<div class="ffxf-modal-frame modal_generate_category">
<div class="ffxf-modal">
<div class="ffxf-modal-inset">
<div class="button close_category"><i class="dashicons dashicons-no-alt"></i></div>
<div class="ffxf-modal-body">
<h2><?php echo __( 'Bulk generate SKU by Category', 'easy-woocommerce-auto-sku-generator' ); ?></h2>
<p id="text_generate_modal"><?php echo __( 'If you saved the general settings, you can continue. Based on the saved settings, the next step will be performed. To get started, select a category and then click on "Generate SKU by Category". If you check the box "Re-create existing SKUs?" then SKU will be recreated.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<?php echo wc_product_dropdown_categories(); ?>
<br>
<button class="generate_button_category"><?php echo __( 'Generate SKU by Category', 'easy-woocommerce-auto-sku-generator' ); ?></button>
<label for="check_generate_category" id="check_gen">
<input id="check_generate_category" name="check_generate_category" type="checkbox" class="checkbox check_generate_on"> <?php echo __( 'Re-create existing SKUs?', 'easy-woocommerce-auto-sku-generator' ); ?>
</label>
<div class="progress-pie-chart" data-percent="1" style="display:none">
<div class="ppc-progress">
<div class="ppc-progress-fill"></div>
</div>
<div class="ppc-percents">
<div class="pcc-percents-wrapper">
<span id="chet">%</span>
</div>
</div>
</div>
<p class="ps"><?php echo __( 'There are', 'easy-woocommerce-auto-sku-generator' ); ?> <?php echo wp_count_posts('product')->publish; ?> <?php echo __( 'products in your store.', 'easy-woocommerce-auto-sku-generator' ); ?></p>
<div class="over">
<div class="my-posts"></div>
</div>
</div>
</div>
</div>
</div>
<div class="ffxf-modal-overlay"></div>
<?php }
}
add_action( 'admin_footer', 'skuautoffxf_modal_setting', 999 );
/**
* Add generate all product
*/
require_once ( plugin_dir_path(__FILE__) . 'generate_all.php' );
/**
* Add generate all product by category
*/
require_once ( plugin_dir_path(__FILE__) . 'generate_category.php' );
add_action( 'admin_init', 'register_my_setting' );
function register_my_setting() {
register_setting( 'my_options_group', 'my_option_name', 'intval' );
}