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,5 @@
.wordpress-org/ export-ignore
.gitignore export-ignore
.github export-ignore
README.md export-ignore
composer.lock export-ignore

View File

@@ -0,0 +1,51 @@
<?php
/*
Plugin Name: EAN for WooCommerce
Plugin URI: https://wpfactory.com/item/ean-for-woocommerce/
Description: Manage product GTIN (EAN, UPC, ISBN, etc.) in WooCommerce. Beautifully.
Version: 4.8.3
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: ean-for-woocommerce
Domain Path: /langs
WC tested up to: 8.2
*/
defined( 'ABSPATH' ) || exit;
if ( 'ean-for-woocommerce.php' === basename( __FILE__ ) ) {
/**
* Check if Pro plugin version is activated.
*
* @version 4.7.3
* @since 2.2.0
*/
$plugin = 'ean-for-woocommerce-pro/ean-for-woocommerce-pro.php';
if (
in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) ||
( is_multisite() && array_key_exists( $plugin, (array) get_site_option( 'active_sitewide_plugins', array() ) ) )
) {
defined( 'ALG_WC_EAN_FILE_FREE' ) || define( 'ALG_WC_EAN_FILE_FREE', __FILE__ );
return;
}
}
defined( 'ALG_WC_EAN_VERSION' ) || define( 'ALG_WC_EAN_VERSION', '4.8.3' );
defined( 'ALG_WC_EAN_FILE' ) || define( 'ALG_WC_EAN_FILE', __FILE__ );
require_once( 'includes/class-alg-wc-ean.php' );
if ( ! function_exists( 'alg_wc_ean' ) ) {
/**
* Returns the main instance of Alg_WC_EAN to prevent the need to use globals.
*
* @version 1.0.0
* @since 1.0.0
*/
function alg_wc_ean() {
return Alg_WC_EAN::instance();
}
}
add_action( 'plugins_loaded', 'alg_wc_ean' );

View File

@@ -0,0 +1,44 @@
<?php
/**
* EAN for WooCommerce - Admin Class
*
* @version 3.6.0
* @since 3.6.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Admin' ) ) :
class Alg_WC_EAN_Admin {
/**
* Constructor.
*
* @version 3.6.0
* @since 3.6.0
*/
function __construct() {
if ( 'no' === get_option( 'alg_wc_ean_duplicate_product', 'yes' ) ) {
add_filter( 'woocommerce_duplicate_product_exclude_meta', array( $this, 'duplicate_product_exclude_meta' ) );
}
}
/**
* duplicate_product_exclude_meta.
*
* @version 3.6.0
* @since 3.6.0
*/
function duplicate_product_exclude_meta( $meta ) {
$meta[] = alg_wc_ean()->core->ean_key;
return $meta;
}
}
endif;
return new Alg_WC_EAN_Admin();

View File

@@ -0,0 +1,622 @@
<?php
/**
* EAN for WooCommerce - Compatibility Class
*
* @version 4.7.7
* @since 2.2.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Compatibility' ) ) :
class Alg_WC_EAN_Compatibility {
/**
* Constructor.
*
* @version 4.7.7
* @since 2.2.0
*
* @todo (dev) MultiVendorX: generate button
* @todo (dev) MultiVendorX: customizable template
* @todo (dev) MultiVendorX: barcodes?
* @todo (dev) "Point of Sale for WooCommerce": add `( 'yes' === get_option( 'alg_wc_ean_wc_pos', 'yes' ) )` / "This will add EAN field to the "Register > Scanning Fields" option of the %s plugin." / Point of Sale for WooCommerce / https://woocommerce.com/products/point-of-sale-for-woocommerce/
* @todo (feature) WCFM: customizable position, i.e., instead of right below the "SKU" field in "Inventory" tab
* @todo (feature) Dokan: customizable position, i.e., instead of `dokan_new_product_after_product_tags` and `dokan_product_edit_after_product_tags`
* @todo (feature) https://wordpress.org/plugins/woocommerce-xml-csv-product-import/ (WooCommerce add-on for "WP All Import")
*/
function __construct() {
// Google Listings & Ads
if ( 'yes' === get_option( 'alg_wc_ean_gla', 'no' ) ) {
add_filter( 'woocommerce_gla_attribute_mapping_sources_custom_attributes', array( $this, 'gla_add_ean' ), PHP_INT_MAX );
}
// MultiVendorX
if ( 'yes' === get_option( 'alg_wc_ean_mvx', 'no' ) ) {
add_action( 'mvx_process_product_object', array( $this, 'mvx_save_ean_field' ), 10, 2 );
add_action( 'mvx_frontend_dashboard_after_product_excerpt_metabox_panel', array( $this, 'mvx_add_ean_field' ) );
}
// "Point of Sale for WooCommerce" plugin
add_filter( 'wc_pos_scanning_fields', array( $this, 'wc_pos_scanning_fields' ), PHP_INT_MAX );
if ( 'yes' === get_option( 'alg_wc_ean_wc_pos_search', 'no' ) ) {
add_filter( 'woocommerce_rest_prepare_product_object', array( $this, 'wc_pos_add_ean_to_product_name' ), PHP_INT_MAX, 3 );
}
// "Woocommerce OpenPos" plugin
add_filter( 'op_barcode_key_setting', array( $this, 'op_barcode_key_setting' ), PHP_INT_MAX );
// "Dokan Best WooCommerce Multivendor Marketplace Solution Build Your Own Amazon, eBay, Etsy" plugin
if ( 'yes' === get_option( 'alg_wc_ean_dokan', 'no' ) ) {
add_action( 'dokan_new_product_after_product_tags', array( $this, 'dokan_add_ean_field' ) );
add_action( 'dokan_product_edit_after_product_tags', array( $this, 'dokan_add_ean_field' ), 10, 2 );
add_action( 'dokan_new_product_added', array( $this, 'dokan_save_ean_field' ), 10, 2 );
add_action( 'dokan_product_updated', array( $this, 'dokan_save_ean_field' ), 10, 2 );
add_action( 'dokan_product_after_variation_pricing', array( $this, 'dokan_add_ean_field_variation' ), 10, 3 );
}
// WCFM
if ( 'yes' === get_option( 'alg_wc_ean_wcfm', 'no' ) ) {
add_filter( 'wcfm_product_fields_stock', array( $this, 'wcfm_add_ean_field' ), 10, 3 );
add_action( 'after_wcfm_products_manage_meta_save', array( $this, 'wcfm_save_ean_field' ), 10, 2 );
// Variations
add_filter( 'wcfm_variation_edit_data', array( $this, 'wcfm_variation_edit_data' ), 10, 3 );
add_filter( 'wcfm_product_manage_fields_variations', array( $this, 'wcfm_variation_add_ean_field' ) );
add_action( 'after_wcfm_product_variation_meta_save', array( $this, 'wcfm_variation_save_ean_field' ), 10, 3 );
}
// "Print Invoice & Delivery Notes for WooCommerce" plugin
if ( 'yes' === get_option( 'alg_wc_ean_wcdn', 'no' ) ) {
add_action( 'wcdn_order_item_after', array( $this, 'add_to_wcdn_ean' ), 10, 3 );
}
// "WooCommerce PDF Invoices & Packing Slips" plugin
if ( 'yes' === get_option( 'alg_wc_ean_wpo_wcpdf', 'no' ) ) {
add_action( get_option( 'alg_wc_ean_wpo_wcpdf_position', 'wpo_wcpdf_after_item_meta' ), array( $this, 'add_to_wpo_wcpdf_ean' ), 10, 3 );
}
// "WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels" plugin
if ( 'yes' === get_option( 'alg_wc_ean_wt_pklist', 'no' ) ) {
// Options
$this->wt_pklist_options = array_replace(
array(
'content' => '<p>EAN: [alg_wc_ean]</p>',
'position' => 'after_product_meta',
'documents' => '',
'column_title' => __( 'EAN', 'ean-for-woocommerce' ),
'column_class' => 'wfte_product_table_head_ean wfte_text_center',
'column_style' => '',
),
get_option( 'alg_wc_ean_wt_pklist_options', array() )
);
// Hooks
switch ( $this->wt_pklist_options['position'] ) {
case 'column':
add_filter( 'wf_pklist_package_product_table_additional_column_val', array( $this, 'add_to_wt_pklist_column_ean' ), 10, 6 );
add_filter( 'wf_pklist_product_table_additional_column_val', array( $this, 'add_to_wt_pklist_column_ean' ), 10, 6 );
add_filter( 'wf_pklist_alter_product_table_head', array( $this, 'add_to_wt_pklist_column_head_ean' ), 10, 3 );
break;
case 'before_product_meta':
case 'after_product_meta':
add_filter( 'wf_pklist_add_product_meta', array( $this, 'add_to_wt_pklist_ean' ), 10, 5 );
add_filter( 'wf_pklist_add_package_product_meta', array( $this, 'add_to_wt_pklist_ean' ), 10, 5 );
break;
default: // 'after_product_name', 'before_product_name'
add_filter( 'wf_pklist_alter_product_name', array( $this, 'add_to_wt_pklist_ean' ), 10, 5 );
add_filter( 'wf_pklist_alter_package_product_name', array( $this, 'add_to_wt_pklist_ean' ), 10, 5 );
}
}
// "WooCommerce Google Product Feed"
add_filter( 'woocommerce_gpf_custom_field_list', array( $this, 'add_to_woocommerce_gpf_custom_field_list' ), PHP_INT_MAX );
// "WooCommerce Customer / Order / Coupon Export"
if ( 'yes' === get_option( 'alg_wc_ean_wc_customer_order_export', 'no' ) ) {
add_filter( 'wc_customer_order_export_format_data_sources', array( $this, 'wc_customer_order_export_add_column' ), 10, 3 );
add_filter( 'wc_customer_order_export_csv_order_row_one_row_per_item', array( $this, 'wc_customer_order_export_render_column' ), 10, 4 );
}
}
/**
* gla_add_ean.
*
* @version 4.7.7
* @since 4.7.5
*/
function gla_add_ean( $values ) {
$values[] = alg_wc_ean()->core->ean_key;
return $values;
}
/**
* mvx_save_ean_field.
*
* @version 4.7.3
* @since 4.7.3
*/
function mvx_save_ean_field( $product, $_post ) {
if ( isset( $_post['alg_wc_ean_mvx'] ) ) {
$product->update_meta_data( alg_wc_ean()->core->ean_key, wc_clean( $_post['alg_wc_ean_mvx'] ) );
}
}
/**
* mvx_add_ean_field.
*
* @version 4.7.3
* @since 4.7.3
*/
function mvx_add_ean_field( $post_id ) {
$title = get_option( 'alg_wc_ean_mvx_title', __( 'EAN:', 'ean-for-woocommerce' ) );
$placeholder = get_option( 'alg_wc_ean_mvx_placeholder', '' );
$value = alg_wc_ean()->core->get_ean( $post_id );
?>
<div class="add-product-info-holder row-padding">
<label for="alg_wc_ean_mvx"><?php echo esc_html( $title ); ?></label>
<input id="alg_wc_ean_mvx" name="alg_wc_ean_mvx" class="form-control inline-input" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>">
</div>
<?php
}
/**
* op_barcode_key_setting.
*
* @version 4.2.0
* @since 4.2.0
*
* @todo (desc) add to "WooCommerce > Settings > EAN > Compatibility"?
*/
function op_barcode_key_setting( $keys ) {
$keys[ alg_wc_ean()->core->ean_key ] = get_option( 'alg_wc_ean_title', esc_html__( 'EAN', 'ean-for-woocommerce' ) );
return $keys;
}
/**
* wc_customer_order_export_add_column.
*
* @version 3.8.0
* @since 3.8.0
*
* @todo (dev) `item_ean` to `item_alg_wc_ean`?
* @todo (dev) XML (at least in `OrderLineItems`)?
*/
function wc_customer_order_export_add_column( $data_sources, $export_type, $output_type ) {
if ( 'orders' === $export_type && 'csv' === $output_type ) {
$data_sources[] = 'item_ean';
}
return $data_sources;
}
/**
* wc_customer_order_export_render_column.
*
* @version 3.8.0
* @since 3.8.0
*/
function wc_customer_order_export_render_column( $data, $item, $order, $generator ) {
$data['item_ean'] = ( ! empty( $item['id'] ) && ( $_item = new WC_Order_Item_Product( $item['id'] ) ) ? alg_wc_ean()->core->get_ean_from_order_item( $_item ) : '' );
return $data;
}
/**
* wt_pklist_check_template_type.
*
* @version 3.5.1
* @since 3.5.1
*/
function wt_pklist_check_template_type( $template_type ) {
if ( ! empty( $this->wt_pklist_options['documents'] ) ) {
if ( ! is_array( $this->wt_pklist_options['documents'] ) ) {
$this->wt_pklist_options['documents'] = array_map( 'trim', explode( ',', $this->wt_pklist_options['documents'] ) );
}
return ( in_array( $template_type, $this->wt_pklist_options['documents'] ) );
}
return true;
}
/**
* add_to_wt_pklist_column_head_ean.
*
* @version 3.5.1
* @since 3.5.1
*/
function add_to_wt_pklist_column_head_ean( $columns, $template_type, $order ) {
if ( $this->wt_pklist_check_template_type( $template_type ) ) {
$columns['ean'] = '<th' .
' class="' . $this->wt_pklist_options['column_class'] . '"' .
' style="' . $this->wt_pklist_options['column_style'] . '"' .
' col-type="' . sanitize_key( $this->wt_pklist_options['column_title'] ) . '"' .
'>' . $this->wt_pklist_options['column_title'] . '</th>';
}
return $columns;
}
/**
* add_to_wt_pklist_column_ean.
*
* @version 3.5.1
* @since 3.5.1
*/
function add_to_wt_pklist_column_ean( $value, $template_type, $column_key, $product, $order_item, $order ) {
if ( 'ean' === $column_key ) {
$value = $this->add_to_wt_pklist_ean( $value, $template_type, $product, $order_item, $order );
}
return $value;
}
/**
* add_to_wt_pklist_ean.
*
* @version 3.5.1
* @since 3.5.0
*
* @see https://wordpress.org/plugins/print-invoices-packing-slip-labels-for-woocommerce/
*/
function add_to_wt_pklist_ean( $value, $template_type, $product, $order_item, $order ) {
if ( $this->wt_pklist_check_template_type( $template_type ) ) {
$result = alg_wc_ean()->core->shortcodes->do_shortcode( $this->wt_pklist_options['content'], array( 'product_id' => $product->get_id() ) );
$value = ( in_array( $this->wt_pklist_options['position'], array( 'after_product_meta', 'after_product_name' ) ) ? $value . $result : $result . $value );
}
return $value;
}
/**
* add_to_woocommerce_gpf_custom_field_list.
*
* @version 3.0.0
* @since 3.0.0
*
* @todo (dev) make this optional?
*/
function add_to_woocommerce_gpf_custom_field_list( $fields ) {
$fields[ 'meta:' . alg_wc_ean()->core->ean_key ] = __( 'EAN', 'ean-for-woocommerce' );
return $fields;
}
/**
* add_to_wcdn_ean.
*
* @version 2.6.0
* @since 1.4.0
*
* @todo (feature) customizable wrapper
* @todo (dev) check if valid?
*/
function add_to_wcdn_ean( $product, $order, $item ) {
if ( false !== ( $ean = alg_wc_ean()->core->get_ean_from_order_item( $item ) ) ) {
echo '<small class="ean_wrapper">' . esc_html( get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) ) . ' ' .
'<span class="ean">' . $ean . '</span>' .
'</small>';
}
}
/**
* add_to_wpo_wcpdf_ean.
*
* @version 4.2.0
* @since 2.6.0
*
* @todo (dev) check if valid?
*/
function add_to_wpo_wcpdf_ean( $type, $item, $order ) {
if ( ! empty( $item['item_id'] ) && ( $item = new WC_Order_Item_Product( $item['item_id'] ) ) && false !== ( $ean = alg_wc_ean()->core->get_ean_from_order_item( $item ) ) ) {
$options = get_option( 'alg_wc_ean_wpo_wcpdf_options', array() );
$template = ( isset( $options['content'] ) ? $options['content'] :
'<dl class="meta">' .
'<dt class="ean">' . esc_html( get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) ) . ':' . '</dt>' .
'<dd class="ean">' . '%ean%' . '</dd>' .
'</dl>' );
echo str_replace( '%ean%', $ean, $template );
}
}
/**
* wcfm_save_ean_field.
*
* @version 4.5.0
* @since 2.2.2
*
* @see https://plugins.svn.wordpress.org/wc-frontend-manager/tags/6.5.10/controllers/products-manager/wcfm-controller-products-manage.php
*/
function wcfm_save_ean_field( $new_product_id, $wcfm_products_manage_form_data ) {
$id = 'wcfm_' . alg_wc_ean()->core->ean_key;
if ( isset( $wcfm_products_manage_form_data[ $id ] ) ) {
alg_wc_ean()->core->set_ean( $new_product_id, wc_clean( $wcfm_products_manage_form_data[ $id ] ) );
}
}
/**
* wcfm_add_ean_field.
*
* @version 4.0.0
* @since 2.2.2
*
* @see https://plugins.svn.wordpress.org/wc-frontend-manager/tags/6.5.10/views/products-manager/wcfm-view-products-manage-tabs.php
*
* @todo (dev) `generate_button`: move `add_action` (3x) to constructor?
* @todo (dev) do we need `esc_html` everywhere, e.g., in `hints`? (same for `dokan_add_ean_field()`)
* @todo (feature) optional EAN validation
*/
function wcfm_add_ean_field( $fields, $product_id, $product_type ) {
$_key = 'wcfm_' . alg_wc_ean()->core->ean_key;
// "Generate" button
$do_add_generate_button = ( 'yes' === get_option( 'alg_wc_ean_wcfm_add_generate_button', 'no' ) && $product_id );
if ( $do_add_generate_button ) {
add_action( 'wp_footer', array( 'Alg_WC_EAN_Edit', 'generate_button_js' ) );
add_action( 'wp_ajax_alg_wc_ean_generate_ajax', array( 'Alg_WC_EAN_Edit', 'generate_button_ajax' ) );
add_action( 'wp_footer', array( $this, 'wcfm_generate_button_css' ) );
}
// Field data
$_field = array(
'label' => esc_html( get_option( 'alg_wc_ean_wcfm_title', __( 'EAN', 'ean-for-woocommerce' ) ) ),
'desc' => ( $do_add_generate_button ? '<p class="alg_wc_ean_generate_button_wrapper">' . Alg_WC_EAN_Edit::get_generate_button( $product_id, $_key ) . '</p>' : '' ),
'type' => 'text',
'class' => 'wcfm-text',
'label_class' => 'wcfm_title',
'value' => alg_wc_ean()->core->get_ean( $product_id ),
'hints' => esc_html( get_option( 'alg_wc_ean_wcfm_hints', __( 'The International Article Number (also known as European Article Number or EAN) is a standard describing a barcode symbology and numbering system used in global trade to identify a specific retail product type, in a specific packaging configuration, from a specific manufacturer.', 'ean-for-woocommerce' ) ) ),
'placeholder' => esc_html( get_option( 'alg_wc_ean_wcfm_placeholder', __( 'Product EAN...', 'ean-for-woocommerce' ) ) ),
);
// Add field
$_fields = array();
$is_added = false;
foreach ( $fields as $key => $field ) {
$_fields[ $key ] = $field;
if ( 'sku' === $key ) {
$_fields[ $_key ] = $_field;
$is_added = true;
}
}
if ( ! $is_added ) {
$_fields[ $_key ] = $_field; // fallback
}
return $_fields;
}
/**
* wcfm_generate_button_css.
*
* @version 4.0.0
* @since 4.0.0
*
* @todo (dev) use `admin_enqueue_scripts`?
*/
function wcfm_generate_button_css() {
?><style>
.alg_wc_ean_generate_button_wrapper {
text-align: right;
}
</style><?php
}
/**
* wcfm_variation_save_ean_field.
*
* @version 4.5.0
* @since 4.0.0
*
* @todo (dev) merge with `wcfm_save_ean_field()`?
*/
function wcfm_variation_save_ean_field( $product_id, $variation_id, $data ) {
$id = 'wcfm_' . alg_wc_ean()->core->ean_key;
if ( isset( $data[ $id ] ) ) {
alg_wc_ean()->core->set_ean( $variation_id, wc_clean( $data[ $id ] ) );
}
}
/**
* wcfm_variation_add_ean_field.
*
* @version 4.0.0
* @since 4.0.0
*
* @todo (dev) placeholder: parent product's EAN?
* @todo (dev) `wcfm_half_ele`?
* @todo (dev) `generate_button`: move `add_action` to constructor?
* @todo (dev) merge with `wcfm_add_ean_field()`?
*/
function wcfm_variation_add_ean_field( $fields ) {
// "Generate" button
if ( 'yes' === get_option( 'alg_wc_ean_wcfm_add_generate_button', 'no' ) ) {
add_action( 'wp_footer', array( $this, 'wcfm_variation_get_generate_button_js' ) );
}
// Field data
$_field = array(
'label' => esc_html( get_option( 'alg_wc_ean_wcfm_title', __( 'EAN', 'ean-for-woocommerce' ) ) ),
'type' => 'text',
'class' => 'wcfm-text wcfm_ele wcfm_half_ele variable variable-subscription pw-gift-card',
'label_class' => 'wcfm_title wcfm_half_ele_title',
'hints' => esc_html( get_option( 'alg_wc_ean_wcfm_hints', __( 'The International Article Number (also known as European Article Number or EAN) is a standard describing a barcode symbology and numbering system used in global trade to identify a specific retail product type, in a specific packaging configuration, from a specific manufacturer.', 'ean-for-woocommerce' ) ) ),
'placeholder' => esc_html( get_option( 'alg_wc_ean_wcfm_placeholder', __( 'Product EAN...', 'ean-for-woocommerce' ) ) ),
);
// Add field
$_fields = array();
$_key = 'wcfm_' . alg_wc_ean()->core->ean_key;
$is_added = false;
foreach ( $fields as $key => $field ) {
$_fields[ $key ] = $field;
if ( 'sku' === $key ) {
$_fields[ $_key ] = $_field;
$is_added = true;
}
}
if ( ! $is_added ) {
$_fields[ $_key ] = $_field; // fallback
}
return $_fields;
}
/**
* wcfm_variation_edit_data.
*
* @version 4.0.0
* @since 4.0.0
*/
function wcfm_variation_edit_data( $variations, $variation_id, $variation_id_key ) {
if ( $variation_id ) {
$variations[ $variation_id_key ][ 'wcfm_' . alg_wc_ean()->core->ean_key ] = alg_wc_ean()->core->get_ean( $variation_id );
}
return $variations;
}
/**
* wcfm_variation_get_generate_button_js.
*
* @version 4.0.0
* @since 4.0.0
*
* @todo (dev) merge with `Alg_WC_EAN_Edit::get_generate_button()`?
*/
function wcfm_variation_get_generate_button_js() {
$button_label = sprintf( esc_html__( 'Generate %s', 'ean-for-woocommerce' ), get_option( 'alg_wc_ean_title', esc_html__( 'EAN', 'ean-for-woocommerce' ) ) );
?><script>
jQuery( document ).ready( function () {
jQuery( '.variation_id' ).each( function () {
var variation_id = jQuery( this ).val();
var input_id = jQuery( this ).attr( 'id' ).replace( 'variations_id_', 'variations_wcfm_' + '<?php echo alg_wc_ean()->core->ean_key; ?>' + '_' );
jQuery( '#' + input_id ).after( '<p class="alg_wc_ean_generate_button_wrapper">' +
'<button' +
' type="button"' +
' class="button alg_wc_ean_generate_ajax wcfm_ele variable variable-subscription pw-gift-card"' +
' data-product="' + variation_id + '"' +
' data-input="' + input_id + '"' +
'>' +
'<?php echo $button_label; ?>' +
'</button>' +
'</p>'
);
} );
} );
</script><?php
}
/**
* dokan_add_ean_field_variation.
*
* @version 4.4.6
* @since 3.1.2
*/
function dokan_add_ean_field_variation( $loop, $variation_data, $variation ) {
$key = alg_wc_ean()->core->ean_key;
$id = "variable{$key}_{$loop}";
$name = "variable{$key}[{$loop}]";
$value = alg_wc_ean()->core->get_ean( $variation->ID );
$title = esc_html( get_option( 'alg_wc_ean_dokan_title', __( 'EAN', 'ean-for-woocommerce' ) ) );
$placeholder = alg_wc_ean()->core->get_ean( $variation->post_parent );
$required = ( 'yes' === get_option( 'alg_wc_ean_dokan_required', 'no' ) ? ' required' : '' );
$required_html = ( 'yes' === get_option( 'alg_wc_ean_dokan_required', 'no' ) ? get_option( 'alg_wc_ean_dokan_required_html', '' ) : '' );
$desc = ( '' !== get_option( 'alg_wc_ean_dokan_desc', '' ) ? alg_wc_ean()->core->shortcodes->do_shortcode( get_option( 'alg_wc_ean_dokan_desc', '' ), array( 'ean' => $value, 'product_id' => $variation->ID ) ) : '' );
echo '<div class="dokan-form-group">' .
'<label for="' . $id . '" class="form-label">' . $title . $required_html . '</label>' .
'<input type="text" name="' . $name . '" id="' . $id . '" class="dokan-form-control alg-wc-ean" placeholder="' . $placeholder . '" value="' . $value . '"' . $required . '>' .
$desc .
'</div>';
}
/**
* dokan_save_ean_field.
*
* @version 4.5.0
* @since 2.2.2
*
* @see https://github.com/weDevsOfficial/dokan/blob/v3.2.8/includes/Dashboard/Templates/Products.php#L353
* @see https://github.com/weDevsOfficial/dokan/blob/v3.2.8/includes/Dashboard/Templates/Products.php#L482
* @see https://github.com/weDevsOfficial/dokan/blob/v3.2.8/includes/Product/functions.php#L127
* @see https://github.com/weDevsOfficial/dokan/blob/v3.2.8/includes/Product/functions.php#L129
* @see https://github.com/weDevsOfficial/dokan/blob/v3.2.8/includes/REST/Manager.php#L172
*
* @todo (dev) `alg_wc_ean_dokan_required`: add server-side validation
*/
function dokan_save_ean_field( $product_id, $data ) {
$id = 'dokan_' . alg_wc_ean()->core->ean_key;
if ( isset( $data[ $id ] ) ) {
alg_wc_ean()->core->set_ean( $product_id, wc_clean( $data[ $id ] ) );
}
}
/**
* dokan_add_ean_field.
*
* @version 4.4.6
* @since 2.2.2
*
* @see https://github.com/weDevsOfficial/dokan/blob/v3.2.8/templates/products/new-product.php#L257
* @see https://github.com/weDevsOfficial/dokan/blob/v3.2.8/templates/products/tmpl-add-product-popup.php#L148
* @see https://github.com/weDevsOfficial/dokan/blob/v3.2.8/templates/products/new-product-single.php#L338
*
* @todo (feature) JS EAN validation?
*/
function dokan_add_ean_field( $post = false, $post_id = false ) {
$id = 'dokan_' . alg_wc_ean()->core->ean_key;
$value = ( ! empty( $post_id ) ? alg_wc_ean()->core->get_ean( $post_id ) : ( isset( $_REQUEST[ $id ] ) ? esc_html( wc_clean( $_REQUEST[ $id ] ) ) : '' ) ); // Edit product vs Add product
$title = esc_html( get_option( 'alg_wc_ean_dokan_title', __( 'EAN', 'ean-for-woocommerce' ) ) );
$placeholder = esc_html( get_option( 'alg_wc_ean_dokan_placeholder', __( 'Product EAN...', 'ean-for-woocommerce' ) ) );
$required = ( 'yes' === get_option( 'alg_wc_ean_dokan_required', 'no' ) ? ' required' : '' );
$required_html = ( 'yes' === get_option( 'alg_wc_ean_dokan_required', 'no' ) ? get_option( 'alg_wc_ean_dokan_required_html', '' ) : '' );
$desc = ( '' !== get_option( 'alg_wc_ean_dokan_desc', '' ) ? alg_wc_ean()->core->shortcodes->do_shortcode( get_option( 'alg_wc_ean_dokan_desc', '' ), array( 'ean' => $value, 'product_id' => $post_id ) ) : '' );
echo '<div class="dokan-form-group">' .
'<label for="' . $id . '" class="form-label">' . $title . $required_html . '</label>' .
'<input type="text" name="' . $id . '" id="' . $id . '" class="dokan-form-control alg-wc-ean" placeholder="' . $placeholder . '" value="' . $value . '"' . $required . '>' .
$desc .
'</div>';
}
/**
* wc_pos_scanning_fields.
*
* Adds "EAN" field to the "Scanning Fields" option in "Point of Sale > Settings > Register".
*
* @version 2.2.0
* @since 2.2.0
*
* @see https://woocommerce.com/products/point-of-sale-for-woocommerce/
*/
function wc_pos_scanning_fields( $fields ) {
$fields[ alg_wc_ean()->core->ean_key ] = __( 'EAN', 'ean-for-woocommerce' );
return $fields;
}
/**
* wc_pos_add_ean_to_product_name.
*
* @version 3.8.0
* @since 3.8.0
*
* @see https://woocommerce.com/products/point-of-sale-for-woocommerce/
*
* @todo (dev) `get_route()`: better solution, e.g., exact match with `/wc-pos/products`?
* @todo (dev) find better solution, e.g., add elsewhere, not to the name?
*/
function wc_pos_add_ean_to_product_name( $response, $product, $request ) {
if ( ( false !== strpos( $request->get_route(), '/wc-pos/' ) ) && '' !== ( $ean = alg_wc_ean()->core->get_ean( $product->get_id() ) ) ) {
$response->data['name'] .= ' (' . sprintf( __( 'EAN: %s', 'ean-for-woocommerce' ), $ean ) . ')';
}
return $response;
}
}
endif;
return new Alg_WC_EAN_Compatibility();

View File

@@ -0,0 +1,328 @@
<?php
/**
* EAN for WooCommerce - Core Class
*
* @version 4.7.0
* @since 1.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Core' ) ) :
class Alg_WC_EAN_Core {
/**
* public.
*
* @version 4.7.0
* @since 1.0.0
*/
public $ean_key;
public $edit;
public $admin;
public $search;
public $display;
public $order_items_table;
public $import_export;
public $orders;
public $rest_api;
public $product_tools;
public $order_tools;
public $settings_import_export;
public $compatibility;
public $shortcodes;
/**
* Constructor.
*
* @version 4.0.0
* @since 1.0.0
*
* @todo (dev) wpml-config.xml?
* @todo (dev) `alg_wc_ean_meta_key`: search for `alg_ean`
* @todo (dev) WPML/Polylang (use default language product ID)
*/
function __construct() {
$this->ean_key = get_option( 'alg_wc_ean_meta_key', '_alg_ean' );
if ( 'yes' === get_option( 'alg_wc_ean_plugin_enabled', 'yes' ) ) {
$this->edit = require_once( 'class-alg-wc-ean-edit.php' );
$this->admin = require_once( 'class-alg-wc-ean-admin.php' );
$this->search = require_once( 'class-alg-wc-ean-search.php' );
$this->display = require_once( 'class-alg-wc-ean-display.php' );
$this->order_items_table = require_once( 'class-alg-wc-ean-order-items-table.php' );
$this->import_export = require_once( 'class-alg-wc-ean-export-import.php' );
$this->orders = require_once( 'class-alg-wc-ean-orders.php' );
$this->rest_api = require_once( 'class-alg-wc-ean-rest-api.php' );
$this->product_tools = require_once( 'class-alg-wc-ean-product-tools.php' );
$this->order_tools = require_once( 'class-alg-wc-ean-order-tools.php' );
$this->settings_import_export = require_once( 'class-alg-wc-ean-manage-settings.php' );
$this->compatibility = require_once( 'class-alg-wc-ean-compatibility.php' );
$this->shortcodes = require_once( 'class-alg-wc-ean-shortcodes.php' );
}
// Core loaded
do_action( 'alg_wc_ean_core_loaded', $this );
}
/**
* get_default_template.
*
* @version 4.6.0
* @since 4.6.0
*
* @todo (dev) move to another file
*/
function get_default_template() {
return sprintf( '%s: %%ean%%', get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) );
}
/**
* get_type.
*
* @version 2.4.0
* @since 1.5.0
*/
function get_type( $ean, $do_match_auto_type = true, $product_id = false ) {
$raw_type = get_option( 'alg_wc_ean_type', 'EAN13' );
$type = ( 'AUTO' === $raw_type && $do_match_auto_type ? $this->get_type_by_ean_length( $ean ) : $raw_type );
return apply_filters( 'alg_wc_ean_get_type', $type, $raw_type, $ean, $product_id );
}
/**
* get_type_by_ean_length.
*
* @version 4.7.0
* @since 1.5.0
*
* @todo (dev) rename function?
*/
function get_type_by_ean_length( $ean ) {
$length = strlen( $ean );
switch ( $length ) {
case 8:
return 'EAN8';
case 12:
return 'UPCA';
case 13:
return ( $this->is_ean_isbn( $ean ) ? 'ISBN13' : ( $this->is_ean_jan( $ean ) ? 'JAN' : 'EAN13' ) );
case 14:
return 'EAN14';
default:
return false;
}
}
/**
* get_ean_type_length.
*
* @version 3.3.0
* @since 1.4.0
*
* @todo (dev) now used only: `EAN8`, `UPCA`, `EAN13`, `ISBN13`, `JAN`, `EAN14`
*/
function get_ean_type_length( $type ) {
switch ( $type ) {
case 'GTIN8':
case 'EAN8':
return 8;
case 'GTIN12':
case 'UPCA':
return 12;
case 'GTIN13':
case 'EAN13':
case 'ISBN13':
case 'JAN':
return 13;
case 'GTIN14':
case 'EAN14':
return 14;
case 'GSIN':
return 17;
case 'SSCC':
return 18;
}
}
/**
* is_ean_isbn.
*
* @version 3.3.0
* @since 3.3.0
*/
function is_ean_isbn( $value ) {
return in_array( substr( $value, 0, 3 ), array( '978', '979' ) );
}
/**
* is_ean_jan.
*
* @version 3.3.0
* @since 3.3.0
*/
function is_ean_jan( $value ) {
return in_array( substr( $value, 0, 2 ), array( '45', '49' ) );
}
/**
* is_valid_ean.
*
* @version 4.7.0
* @since 1.0.1
*
* @see https://stackoverflow.com/questions/19890144/generate-valid-ean13-in-php
* @see https://stackoverflow.com/questions/29076255/how-do-i-validate-a-barcode-number-using-php
* @see http://www.gs1.org/how-calculate-check-digit-manually
*
* @todo (feature) add more formats/standards, e.g., ASIN, etc.; also see https://github.com/tecnickcom/TCPDF/blob/6.4.1/tcpdf_barcodes_1d.php#L70
*/
function is_valid_ean( $value, $product_id = false ) {
$type = $this->get_type( $value, false, $product_id );
switch ( $type ) {
case 'EAN8': // e.g.: 96385074
case 'UPCA': // e.g.: 042100005264
case 'EAN13': // e.g.: 5901234123457
case 'ISBN13':
case 'JAN':
case 'EAN14': // e.g.: 40700719670720
case 'AUTO':
$ean = ( string ) $value;
// We accept only digits
if ( ! preg_match( "/^[0-9]+$/", $ean ) ) {
$result = false;
break;
}
// Check valid lengths
$l = strlen( $ean );
if ( ( 'AUTO' == $type && ! in_array( $l, array( 8, 12, 13 ) ) ) || ( 'AUTO' != $type && $l != $this->get_ean_type_length( $type ) ) ) {
$result = false;
break;
}
// Get check digit
$check = substr( $ean, -1 );
$ean = substr( $ean, 0, -1 );
$sum_even = $sum_odd = 0;
$even = true;
while ( strlen( $ean ) > 0 ) {
$digit = substr( $ean, -1 );
if ( $even ) {
$sum_even += 3 * $digit;
} else {
$sum_odd += $digit;
}
$even = ! $even;
$ean = substr( $ean, 0, -1 );
}
$sum = $sum_even + $sum_odd;
$sum_rounded_up = ceil( $sum / 10 ) * 10;
$result = ( $check == ( $sum_rounded_up - $sum ) );
// Extra prefix check (ISBN13, JAN)
if ( $result ) {
if ( 'ISBN13' === $type ) {
if ( ! $this->is_ean_isbn( $value ) ) {
$result = false;
}
} elseif ( 'JAN' === $type ) {
if ( ! $this->is_ean_jan( $value ) ) {
$result = false;
}
}
}
break;
default:
$result = ( 0 != strlen( $value ) );
}
return apply_filters( 'alg_wc_ean_is_valid', $result, $value, $type );
}
/**
* do_ean_exist.
*
* @version 3.6.0
* @since 3.6.0
*/
function do_ean_exist( $ean, $not_product_id = false ) {
$args = array(
'meta_key' => $this->ean_key,
'meta_value' => $ean,
'post_type' => array( 'product', 'product_variation' ),
'post__not_in' => ( $not_product_id ? array( $not_product_id ) : array() ),
'fields' => 'ids',
);
$query = new WP_Query( $args );
return $query->have_posts();
}
/**
* get_ean_from_order_item.
*
* @version 2.4.0
* @since 1.2.0
*
* @todo (dev) move to `Alg_WC_EAN_Orders`?
*/
function get_ean_from_order_item( $item ) {
return ( is_a( $item, 'WC_Order_Item_Product' ) && (
'' !== ( $ean = wc_get_order_item_meta( $item->get_id(), $this->ean_key ) ) || // from order item meta
( ( $product_id = $this->get_order_item_product_id( $item ) ) && '' !== ( $ean = $this->get_ean( $product_id ) ) ) // from product directly
) ? $ean : false );
}
/**
* get_order_item_product_id.
*
* @version 2.4.0
* @since 2.4.0
*
* @todo (dev) move to `Alg_WC_EAN_Orders`?
* @todo (dev) `if ( ! is_a( $item, 'WC_Order_Item_Product' ) )` try `( $item = new WC_Order_Item_Product( $item['item_id'] ) )`?
*/
function get_order_item_product_id( $item ) {
return ( is_a( $item, 'WC_Order_Item_Product' ) ?
( 0 != ( $variation_id = $item->get_variation_id() ) ? $variation_id : ( 0 != ( $_product_id = $item->get_product_id() ) ? $_product_id : false ) ) :
false
);
}
/**
* get_ean.
*
* @version 1.0.0
* @since 1.0.0
*
* @todo (dev) use `$do_try_parent`?
* @todo (dev) rethink `$product_id`?
*/
function get_ean( $product_id = false, $do_try_parent = false ) {
if ( ! $product_id ) {
$product_id = get_the_ID();
}
$ean = get_post_meta( $product_id, $this->ean_key, true );
if ( '' === $ean && $do_try_parent && 0 != ( $parent_id = wp_get_post_parent_id( $product_id ) ) ) {
$ean = get_post_meta( $parent_id, $this->ean_key, true );
}
return $ean;
}
/**
* set_ean.
*
* @version 4.5.0
* @since 4.5.0
*/
function set_ean( $product_id, $value ) {
return update_post_meta( $product_id, $this->ean_key, $value );
}
}
endif;
return new Alg_WC_EAN_Core();

View File

@@ -0,0 +1,429 @@
<?php
/**
* EAN for WooCommerce - Display Class
*
* @version 4.7.5
* @since 2.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Display' ) ) :
class Alg_WC_EAN_Display {
/**
* Constructor.
*
* @version 4.4.5
* @since 2.0.0
*
* @todo (dev) Admin products list column: move to `class-alg-wc-ean-display-admin.php` or `class-alg-wc-ean-admin.php`?
* @todo (dev) remove `! is_admin()` and `is_admin()`?
* @todo (feature) frontend: customizable position and template for loop, cart, etc. (now implemented for "single product page" only)
* @todo (dev) frontend: order?
*/
function __construct() {
// Frontend
if ( ! is_admin() || wp_doing_ajax() ) {
// Single product page
if ( 'yes' === get_option( 'alg_wc_ean_frontend', 'yes' ) ) {
$positions_priorities = get_option( 'alg_wc_ean_frontend_positions_priorities', array() );
foreach ( get_option( 'alg_wc_ean_frontend_positions', array( 'woocommerce_product_meta_start' ) ) as $position ) {
add_action( $position, array( $this, 'add_ean_single' ), ( isset( $positions_priorities[ $position ] ) ? $positions_priorities[ $position ] : 10 ) );
}
// Variations
add_action( 'wp_enqueue_scripts', array( $this, 'variations_enqueue_scripts' ) );
add_filter( 'woocommerce_available_variation', array( $this, 'variations_add_params' ), 10, 3 );
}
// Loop
if ( 'yes' === get_option( 'alg_wc_ean_frontend_loop', 'no' ) ) {
add_action( 'woocommerce_after_shop_loop_item_title', array( $this, 'add_ean_loop' ) );
}
// Cart
if ( 'yes' === get_option( 'alg_wc_ean_frontend_cart', 'no' ) ) {
add_action( 'woocommerce_after_cart_item_name', array( $this, 'add_ean_cart' ) );
}
// Product structured data
if ( 'yes' === get_option( 'alg_wc_ean_frontend_product_structured_data', 'yes' ) ) {
add_filter( 'woocommerce_structured_data_product', array( $this, 'add_ean_to_product_structured_data' ), 10, 2 );
// "Rank Math SEO" plugin
if ( 'yes' === get_option( 'alg_wc_ean_frontend_product_structured_data_rank_math_seo', 'no' ) ) {
add_filter( 'rank_math/json_ld', array( $this, 'add_ean_to_product_structured_data_rank_math_seo' ), PHP_INT_MAX, 2 );
}
}
}
// Backend
if ( is_admin() ) {
// Admin products list column
if ( 'yes' === get_option( 'alg_wc_ean_backend_column', 'yes' ) ) {
add_filter( 'manage_edit-product_columns', array( $this, 'add_product_columns' ) );
add_action( 'manage_product_posts_custom_column', array( $this, 'render_product_columns' ), 10, 2 );
add_filter( 'manage_edit-product_sortable_columns', array( $this, 'product_sortable_columns' ) );
add_action( 'pre_get_posts', array( $this, 'product_columns_order_by_column' ) );
add_action( 'admin_head', array( $this, 'product_columns_style' ) );
}
}
}
/**
* add_ean_to_product_structured_data_rank_math_seo.
*
* @version 3.7.0
* @since 3.7.0
*
* @see https://wordpress.org/plugins/seo-by-rank-math/
*
* @todo (dev) simplify?
* @todo (dev) move to the "Compatibility" class (and settings section)?
*/
function add_ean_to_product_structured_data_rank_math_seo( $data, $json_ld = false ) {
if (
! empty( $data['richSnippet']['@type'] ) && 'Product' === $data['richSnippet']['@type'] &&
( ! empty( $json_ld->post_id ) || ! empty( $json_ld->post->ID ) )
) {
$product_id = ( ! empty( $json_ld->post_id ) ? $json_ld->post_id : $json_ld->post->ID );
$product = wc_get_product( $product_id );
if ( $product ) {
$_data = $this->add_ean_to_product_structured_data( array(), $product );
if ( ! empty( $_data ) ) {
$data['richSnippet'] = array_merge( $data['richSnippet'], $_data );
}
}
}
return $data;
}
/**
* product_columns_style.
*
* @version 3.0.0
* @since 3.0.0
*
* @todo (dev) make this optional? (same for barcodes)
* @todo (dev) load only on `edit.php?post_type=product` etc.? (same for barcodes)
*/
function product_columns_style() {
?><style>
.column-ean {
width: 10%;
}
</style><?php
}
/**
* product_sortable_columns.
*
* @version 1.5.0
* @since 1.5.0
*/
function product_sortable_columns( $columns ) {
$columns['ean'] = 'alg_ean';
return $columns;
}
/**
* product_columns_order_by_column.
*
* @version 4.7.1
* @since 1.5.0
*
* @todo (dev) `$do_exclude_empty_lines`?
*/
function product_columns_order_by_column( $query ) {
if (
$query->is_main_query() && ( $orderby = $query->get( 'orderby' ) ) && 'alg_ean' === $orderby &&
isset( $query->query['post_type'] ) && in_array( 'product', (array) $query->query['post_type'] ) &&
isset( $query->is_admin ) && 1 == $query->is_admin
) {
$do_exclude_empty_lines = false;
$key = alg_wc_ean()->core->ean_key;
if ( $do_exclude_empty_lines ) {
$query->set( 'meta_key', $key );
} else {
$query->set( 'meta_query', array(
'relation' => 'OR',
array(
'key' => $key,
'compare' => 'NOT EXISTS'
),
array(
'key' => $key,
'compare' => 'EXISTS'
),
) );
}
$query->set( 'orderby', 'meta_value ID' );
}
}
/**
* add_product_columns.
*
* @version 2.2.7
* @since 1.0.0
*
* @todo (dev) `__( 'EAN', 'ean-for-woocommerce' )` -> `'EAN'` (everywhere) (i.e., no translation)?
*/
function add_product_columns( $columns ) {
$is_added = false;
$_columns = array();
foreach ( $columns as $column_key => $column_title ) {
$_columns[ $column_key ] = $column_title;
if ( 'sku' === $column_key ) {
$_columns['ean'] = get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) );
$is_added = true;
}
}
if ( ! $is_added ) {
// Fallback
$_columns['ean'] = get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) );
}
return $_columns;
}
/**
* render_product_column_ean.
*
* @version 2.4.0
* @since 1.0.1
*/
function render_product_column_ean( $do_validate, $ean, $product_id = false ) {
return ( $do_validate && ! alg_wc_ean()->core->is_valid_ean( $ean, $product_id ) ? '<span style="color:red;">' . $ean . '</span>' : $ean );
}
/**
* render_product_columns.
*
* @version 2.4.0
* @since 1.0.0
*/
function render_product_columns( $column, $product_id ) {
if ( 'ean' === $column ) {
$product = wc_get_product( $product_id );
$values = array();
$do_validate = ( 'yes' === get_option( 'alg_wc_ean_backend_column_validate', 'no' ) );
if ( '' != ( $value = alg_wc_ean()->core->get_ean( $product_id ) ) ) {
$values[] = $this->render_product_column_ean( $do_validate, $value, $product_id );
}
if ( $product->is_type( 'variable' ) ) {
foreach ( $product->get_children() as $child_id ) {
if ( '' != ( $value = alg_wc_ean()->core->get_ean( $child_id ) ) ) {
$values[] = $this->render_product_column_ean( $do_validate, $value, $product_id );
}
}
}
if ( ! empty( $values ) ) {
echo implode( ', ', $values );
}
}
}
/**
* add_ean_to_product_structured_data.
*
* @version 4.7.5
* @since 1.0.0
*
* @see https://schema.org/Product
* @see https://github.com/woocommerce/woocommerce/blob/6.3.1/plugins/woocommerce/includes/class-wc-structured-data.php#L328
*
* @todo (dev) what to do if there is no markup data? see: https://github.com/woocommerce/woocommerce/blob/6.3.1/plugins/woocommerce/includes/class-wc-structured-data.php#L324
* @todo (dev) maybe always use `gtin` (... all-numeric string of either 8, 12, 13 or 14 digits...)
* @todo (dev) `default` (`C128`): maybe no markup then?
*/
function add_ean_to_product_structured_data( $markup, $product ) {
// Get & filter product EAN
$value = alg_wc_ean()->core->get_ean( $product->get_id() );
$value = apply_filters( 'alg_wc_ean_product_structured_data_value', $value, $product );
// Add EAN to the markup
if ( '' !== $value || apply_filters( 'alg_wc_ean_product_structured_data_allow_empty_value', false, $product ) ) {
// Get key
if ( 'yes' === get_option( 'alg_wc_ean_frontend_product_structured_data_key_auto', 'yes' ) ) {
$type = alg_wc_ean()->core->get_type( $value, false, $product->get_id() );
switch ( $type ) {
case 'EAN8':
$key = 'gtin8';
break;
case 'UPCA':
$key = 'gtin12';
break;
case 'EAN13':
case 'ISBN13':
case 'JAN':
$key = 'gtin13';
break;
case 'EAN14':
$key = 'gtin14';
break;
default: // e.g., `AUTO`, `C128`
$key = apply_filters( 'alg_wc_ean_product_structured_data_markup_key', 'gtin', $type, $product );
}
} else {
$key = get_option( 'alg_wc_ean_frontend_product_structured_data_key', 'gtin' );
$key = apply_filters( 'alg_wc_ean_product_structured_data_markup_key', $key, false, $product );
}
// Filter & add
$value = apply_filters( 'alg_wc_ean_product_structured_data_markup_value', $value, $product );
if ( '' !== $value ) {
$markup[ $key ] = $value;
}
}
return $markup;
}
/**
* variations_enqueue_scripts.
*
* @version 4.4.0
* @since 1.0.0
*/
function variations_enqueue_scripts() {
if ( 'product_meta' === get_option( 'alg_wc_ean_frontend_variation_position', 'product_meta' ) ) {
wp_enqueue_script( 'alg-wc-ean-variations',
alg_wc_ean()->plugin_url() . '/includes/js/alg-wc-ean-variations' . ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ? '' : '.min' ) . '.js',
array( 'jquery' ),
alg_wc_ean()->version,
true
);
wp_localize_script( 'alg-wc-ean-variations',
'alg_wc_ean_variations_obj', array(
'variations_form' => get_option( 'alg_wc_ean_js_variations_form', '.variations_form' ),
'variations_form_closest' => get_option( 'alg_wc_ean_js_variations_form_closest', '.summary' ),
)
);
}
}
/**
* variations_add_params.
*
* @version 4.6.0
* @since 1.0.0
*/
function variations_add_params( $args, $product = false, $variation = false ) {
if ( $variation ) {
$key = alg_wc_ean()->core->ean_key;
if ( 'product_meta' === get_option( 'alg_wc_ean_frontend_variation_position', 'product_meta' ) ) {
$args['ean'] = $variation->get_meta( $key );
} else {
$args['variation_description'] .= str_replace( '%ean%', $variation->get_meta( $key ),
get_option( 'alg_wc_ean_template', alg_wc_ean()->core->get_default_template() ) );
}
}
return $args;
}
/**
* get_ean_output_data.
*
* @version 2.2.5
* @since 1.1.0
*
* @todo (dev) better solution for variable products
*/
function get_ean_output_data() {
$result = array( 'do_output' => false, 'style' => '', 'value' => alg_wc_ean()->core->get_ean() );
if ( '' !== $result['value'] ) {
$result['do_output'] = true;
} else {
global $product;
if ( $product && $product->is_type( 'variable' ) ) {
$result['do_output'] = true;
$result['style'] = ' style="display:none;"';
}
}
return $result;
}
/**
* add_ean.
*
* @version 4.6.0
* @since 1.0.0
*
* @todo (dev) template: shortcode vs placeholder?
* @todo (dev) customizable wrapping HTML (same for all frontend/backend options) - `ean` class must be present though (for the variations' JS)
* @todo (dev) `esc_html__( 'N/A', 'ean-for-woocommerce' )`
*/
function add_ean( $template, $single_or_loop ) {
$output_data = $this->get_ean_output_data();
if ( $output_data['do_output'] ) {
global $product;
$template = alg_wc_ean()->core->shortcodes->do_shortcode( $template, array( 'product_id' => ( $product ? $product->get_id() : false ) ) );
$ean_html = '<span class="ean">' . $output_data['value'] . '</span>';
$template = str_replace( '%ean%', $ean_html, $template );
$output = '<span class="sku_wrapper ean_wrapper"' . $output_data['style'] . '>' . $template . '</span>';
echo apply_filters( 'alg_wc_ean_display', $output, $output_data['value'], $output_data['style'], $template, $single_or_loop );
}
}
/**
* add_ean_single.
*
* @version 4.6.0
* @since 2.1.0
*/
function add_ean_single() {
$this->add_ean(
get_option( 'alg_wc_ean_template', alg_wc_ean()->core->get_default_template() ),
'single'
);
}
/**
* add_ean_loop.
*
* @version 4.6.0
* @since 2.0.0
*
* @todo (feature) customizable position(s)?
* @todo (dev) variable: implode variations' EANs?
*/
function add_ean_loop() {
$this->add_ean(
get_option( 'alg_wc_ean_template_loop', alg_wc_ean()->core->get_default_template() ),
'loop'
);
}
/**
* add_ean_cart.
*
* @version 2.0.0
* @since 2.0.0
*
* @todo (dev) use `$this->add_ean()`?
*/
function add_ean_cart( $cart_item ) {
$product_id = ( ! empty( $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id'] );
if ( $ean = alg_wc_ean()->core->get_ean( $product_id ) ) {
echo '<div><span class="sku_wrapper ean_wrapper">' . esc_html__( 'EAN:', 'ean-for-woocommerce' ) . ' ' .
'<span class="ean">' . $ean . '</span>' .
'</span></div>';
}
}
}
endif;
return new Alg_WC_EAN_Display();

View File

@@ -0,0 +1,317 @@
<?php
/**
* EAN for WooCommerce - Edit Class
*
* @version 4.8.0
* @since 2.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Edit' ) ) :
class Alg_WC_EAN_Edit {
/**
* Constructor.
*
* @version 4.3.4
* @since 2.0.0
*
* @todo (dev) position: new tab (for both simple and variable products)
*/
function __construct() {
if ( is_admin() && apply_filters( 'alg_wc_ean_edit', true ) ) {
// Admin product edit page
add_action( get_option( 'alg_wc_ean_backend_position', 'woocommerce_product_options_sku' ), array( $this, 'add_ean_input' ) );
add_action( 'save_post_product', array( $this, 'save_ean_input' ), 10, 2 );
// Variations
add_action( get_option( 'alg_wc_ean_backend_position_variation', 'woocommerce_variation_options_pricing' ), array( $this, 'add_ean_input_variation' ), 10, 3 );
add_action( 'woocommerce_save_product_variation', array( $this, 'save_ean_input_variation' ), 10, 2 );
// Quick and Bulk edit
add_action( 'woocommerce_product_quick_edit_end', array( $this, 'add_bulk_and_quick_edit_fields' ), PHP_INT_MAX );
add_action( 'woocommerce_product_bulk_edit_end', array( $this, 'add_bulk_and_quick_edit_fields' ), PHP_INT_MAX );
add_action( 'woocommerce_product_bulk_and_quick_edit', array( $this, 'save_bulk_and_quick_edit_fields' ), PHP_INT_MAX, 2 );
// "Generate" button
$this->do_add_generate_button = ( 'yes' === get_option( 'alg_wc_ean_backend_add_generate_button', 'no' ) );
if ( $this->do_add_generate_button ) {
add_action( 'admin_footer', array( $this, 'add_generate_button' ) );
add_action( 'wp_ajax_alg_wc_ean_generate_ajax', array( $this, 'generate_button_ajax' ) );
}
}
}
/**
* add_generate_button.
*
* @version 4.0.0
* @since 4.0.0
*/
function add_generate_button() {
if ( is_admin() && function_exists( 'get_current_screen' ) && ( $screen = get_current_screen() ) && 'product' === $screen->post_type ) {
$this->generate_button_js();
}
}
/**
* generate_button_js.
*
* @version 4.0.0
* @since 4.0.0
*
* @todo (dev) static? (3x)
* @todo (dev) recheck `return false;`
* @todo (dev) recheck `ajaxurl`
* @todo (dev) use `admin_enqueue_scripts`?
*/
static function generate_button_js() {
?><script>
jQuery( document ).ready( function () {
jQuery( 'body' ).on( 'click', '.alg_wc_ean_generate_ajax', function () {
var product = jQuery( this ).data( 'product' )
var input = jQuery( this ).data( 'input' );
jQuery( '#spinner-' + input ).addClass( 'is-active' );
var data = {
'action': 'alg_wc_ean_generate_ajax',
'product': product,
'input' : input,
};
jQuery.post( ajaxurl, data, function( response ) {
if ( response ) {
jQuery( '#' + data['input'] ).val( response );
}
jQuery( '#spinner-' + data['input'] ).removeClass( 'is-active' );
} );
return false;
} );
} );
</script><?php
}
/**
* generate_button_ajax.
*
* @version 4.0.0
* @since 4.0.0
*/
static function generate_button_ajax() {
echo alg_wc_ean()->core->product_tools->generate_ean( intval( $_POST['product'] ), alg_wc_ean()->core->product_tools->get_generate_data() );
die();
}
/**
* get_generate_button.
*
* @version 4.0.0
* @since 4.0.0
*
* @todo (dev) spinner: styling?
* @todo (dev) spinner: `float: none;`?
* @todo (dev) spinner: wcfm
*/
static function get_generate_button( $product_id, $input_html_id ) {
return '<button' .
' type="button"' .
' class="button' .
' alg_wc_ean_generate_ajax"' .
' data-product="' . $product_id . '"' .
' data-input="' . $input_html_id . '"' .
'>' .
sprintf( esc_html__( 'Generate %s', 'ean-for-woocommerce' ), get_option( 'alg_wc_ean_title', esc_html__( 'EAN', 'ean-for-woocommerce' ) ) ) .
'</button>' .
'<span class="spinner" id="spinner-' . $input_html_id . '" style="float:none;"></span>';
}
/**
* add_bulk_and_quick_edit_fields.
*
* @version 2.2.7
* @since 1.5.0
*
* @todo (dev) reposition this (e.g., right after the "SKU" field)?
* @todo (dev) actual value (instead of "No change" placeholder)? (probably need to add value to `woocommerce_inline_`) (quick edit only?)
*/
function add_bulk_and_quick_edit_fields() {
echo ( 'woocommerce_product_quick_edit_end' === current_filter() ? '<br class="clear" />' : '' ) .
'<label>' .
'<span class="title">' . esc_html( get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) ) . '</span>' .
'<span class="input-text-wrap">' .
'<input type="text" name="_alg_ean_qb" class="text" placeholder="' . __( '- No change -', 'ean-for-woocommerce' ) . '" value="">' .
'</span>' .
'</label>';
}
/**
* save_bulk_and_quick_edit_fields.
*
* @version 4.5.0
* @since 1.5.0
*/
function save_bulk_and_quick_edit_fields( $post_id, $post ) {
// If this is an autosave, our form has not been submitted, so we don't want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// Don't save revisions and autosaves
if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) || 'product' !== $post->post_type || ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
// Check nonce
if ( ! isset( $_REQUEST['woocommerce_quick_edit_nonce'] ) || ! wp_verify_nonce( $_REQUEST['woocommerce_quick_edit_nonce'], 'woocommerce_quick_edit_nonce' ) ) { // WPCS: input var ok, sanitization ok.
return $post_id;
}
// Save
if ( isset( $_REQUEST['_alg_ean_qb'] ) && '' !== $_REQUEST['_alg_ean_qb'] ) {
alg_wc_ean()->core->set_ean( $post_id, wc_clean( $_REQUEST['_alg_ean_qb'] ) );
}
return $post_id;
}
/**
* get_ean_input_desc.
*
* @version 3.6.0
* @since 1.0.1
*
* @todo (dev) replace `style` with `class`
*/
function get_ean_input_desc( $ean, $product_id = false ) {
$desc = array();
if ( 'yes' === get_option( 'alg_wc_ean_backend_is_valid', 'yes' ) ) {
$desc[] = ( alg_wc_ean()->core->is_valid_ean( $ean, $product_id ) ?
'<span style="color:green;">' . esc_html__( 'Valid EAN', 'ean-for-woocommerce' ) . '</span>' :
'<span style="color:red;">' . esc_html__( 'Invalid EAN', 'ean-for-woocommerce' ) . '</span>' );
}
if ( 'yes' === get_option( 'alg_wc_ean_backend_is_unique', 'no' ) ) {
$desc[] = ( ! alg_wc_ean()->core->do_ean_exist( $ean, $product_id ) ?
'<span style="color:green;">' . esc_html__( 'Unique EAN', 'ean-for-woocommerce' ) . '</span>' :
'<span style="color:red;">' . esc_html__( 'Duplicated EAN', 'ean-for-woocommerce' ) . '</span>' );
}
return implode( ' | ', $desc );
}
/**
* get_ean_input_custom_atts.
*
* @version 4.8.0
* @since 1.0.1
*
* @todo (dev) `AUTO`: better maxlength (13); add minlength (8)
* @todo (dev) `ean-13`: `array( 'pattern' => '.{0}|[0-9]{13}', 'maxlength' => '13' ) )`
* @todo (dev) `ean-13`: `array( 'pattern' => '.{0}|[0-9]+', 'minlength' => '13', 'maxlength' => '13' )`
*/
function get_ean_input_custom_atts( $product_id = false, $atts = array() ) {
$result = $atts;
// Required
if ( 'yes' === get_option( 'alg_wc_ean_required', 'no' ) ) {
$result = array_merge( $result, array( 'required' => 'required' ) );
}
// Pattern and max length
$type = false;
if ( 'yes' === get_option( 'alg_wc_ean_add_pattern', 'no' ) ) {
$type = alg_wc_ean()->core->get_type( false, false, $product_id );
switch ( $type ) {
case 'EAN8':
case 'UPCA':
case 'EAN13':
case 'ISBN13':
case 'JAN':
case 'EAN14':
case 'AUTO':
$result = array_merge( $result, array(
'pattern' => '[0-9]+',
'maxlength' => ( 'AUTO' === $type ? 13 : alg_wc_ean()->core->get_ean_type_length( $type ) ),
) );
break;
}
}
// Deprecated filter
$result = apply_filters( 'alg_wc_ean_input_pattern', $result, $atts, $type );
return apply_filters( 'alg_wc_ean_input_custom_atts', $result, $product_id, $atts );
}
/**
* add_ean_input_variation.
*
* @version 4.4.0
* @since 1.0.0
*
* @todo (dev) `variable{$key}` to `variable_{$key}`?
*/
function add_ean_input_variation( $loop, $variation_data, $variation ) {
$key = alg_wc_ean()->core->ean_key;
woocommerce_wp_text_input( array(
'id' => "variable{$key}_{$loop}",
'name' => "variable{$key}[{$loop}]",
'value' => ( isset( $variation_data[ $key ][0] ) ? $variation_data[ $key ][0] : '' ),
'label' => esc_html( get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) ),
'wrapper_class' => 'form-row form-row-full',
'placeholder' => alg_wc_ean()->core->get_ean( $variation->post_parent ),
'description' => ( ! empty( $variation_data[ $key ][0] ) ? $this->get_ean_input_desc( $variation_data[ $key ][0], $variation->ID ) :
( $this->do_add_generate_button ? '<p>' . $this->get_generate_button( $variation->ID, "variable{$key}_{$loop}" ) . '</p>' : '' ) ),
'custom_attributes' => $this->get_ean_input_custom_atts( $variation->ID ),
) );
}
/**
* save_ean_input_variation.
*
* @version 4.5.0
* @since 1.0.0
*/
function save_ean_input_variation( $variation_id, $i ) {
$key = alg_wc_ean()->core->ean_key;
if ( isset( $_POST[ 'variable' . $key ][ $i ] ) ) {
alg_wc_ean()->core->set_ean( $variation_id, wc_clean( $_POST[ 'variable' . $key ][ $i ] ) );
}
}
/**
* add_ean_input.
*
* @version 4.4.0
* @since 1.0.0
*/
function add_ean_input() {
$product_id = get_the_ID();
$value = alg_wc_ean()->core->get_ean( $product_id );
woocommerce_wp_text_input( array(
'id' => alg_wc_ean()->core->ean_key,
'value' => $value,
'label' => esc_html( get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) ),
'description' => ( ! empty( $value ) ? $this->get_ean_input_desc( $value, $product_id ) :
( $this->do_add_generate_button ? $this->get_generate_button( $product_id, alg_wc_ean()->core->ean_key ) : '' ) ),
'custom_attributes' => $this->get_ean_input_custom_atts( $product_id ),
) );
}
/**
* save_ean_input.
*
* @version 4.5.0
* @since 1.0.0
*
* @todo (dev) save `$key . '_is_valid'` (same in `save_ean_input_variation()`)
*/
function save_ean_input( $post_id, $__post ) {
if ( isset( $_POST[ alg_wc_ean()->core->ean_key ] ) && empty( $_REQUEST['woocommerce_quick_edit'] ) && empty( $_REQUEST['woocommerce_bulk_edit'] ) ) {
alg_wc_ean()->core->set_ean( $post_id, wc_clean( $_POST[ alg_wc_ean()->core->ean_key ] ) );
}
}
}
endif;
return new Alg_WC_EAN_Edit();

View File

@@ -0,0 +1,103 @@
<?php
/**
* EAN for WooCommerce - Export Import Class
*
* @version 2.0.0
* @since 2.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Export_Import' ) ) :
class Alg_WC_EAN_Export_Import {
/**
* Constructor.
*
* @version 2.0.0
* @since 2.0.0
*/
function __construct() {
// Export
add_filter( 'woocommerce_product_export_column_names', array( $this, 'add_export_column' ) );
add_filter( 'woocommerce_product_export_product_default_columns', array( $this, 'add_export_column' ) );
add_filter( 'woocommerce_product_export_product_column_alg_ean', array( $this, 'add_export_data' ), 10, 2 );
// Import
add_filter( 'woocommerce_csv_product_import_mapping_options', array( $this, 'add_import_mapping_option' ) );
add_filter( 'woocommerce_csv_product_import_mapping_default_columns', array( $this, 'set_import_mapping_option_default' ) );
add_filter( 'woocommerce_product_importer_parsed_data', array( $this, 'parse_import_data' ), 10, 2 );
}
/**
* parse_import_data.
*
* @version 2.0.0
* @since 1.5.0
*/
function parse_import_data( $data, $importer ) {
if ( isset( $data['alg_ean'] ) ) {
if ( ! isset( $data['meta_data'] ) ) {
$data['meta_data'] = array();
}
$data['meta_data'][] = array(
'key' => alg_wc_ean()->core->ean_key,
'value' => $data['alg_ean'],
);
unset( $data['alg_ean'] );
}
return $data;
}
/**
* set_import_mapping_option_default.
*
* @version 1.5.0
* @since 1.5.0
*
* @todo (dev) use `alg_wc_ean_title` option value instead of 'EAN' (same in `add_import_mapping_option()` and `add_export_column()`)?
*/
function set_import_mapping_option_default( $columns ) {
$columns['EAN'] = 'alg_ean';
return $columns;
}
/**
* add_import_mapping_option.
*
* @version 1.5.0
* @since 1.5.0
*/
function add_import_mapping_option( $options ) {
$options['alg_ean'] = 'EAN';
return $options;
}
/**
* add_export_column.
*
* @version 1.5.0
* @since 1.5.0
*/
function add_export_column( $columns ) {
$columns['alg_ean'] = 'EAN';
return $columns;
}
/**
* add_export_data.
*
* @version 2.0.0
* @since 1.5.0
*/
function add_export_data( $value, $product ) {
return alg_wc_ean()->core->get_ean( $product->get_id() );
}
}
endif;
return new Alg_WC_EAN_Export_Import();

View File

@@ -0,0 +1,113 @@
<?php
/**
* EAN for WooCommerce - Settings Import/Export/Reset Class
*
* @version 4.0.0
* @since 3.9.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Manage_Settings' ) ) :
class Alg_WC_EAN_Manage_Settings {
/**
* Constructor.
*
* @version 4.0.0
* @since 3.9.0
*/
function __construct() {
add_action( 'alg_wc_ean_settings_saved', array( $this, 'export_settings' ) );
add_action( 'alg_wc_ean_settings_saved', array( $this, 'import_settings' ) );
add_action( 'alg_wc_ean_settings_saved', array( $this, 'reset_settings' ) );
}
/**
* reset_settings.
*
* @version 4.0.0
* @since 4.0.0
*/
function reset_settings() {
if ( 'yes' === get_option( 'alg_wc_ean_reset_settings', 'no' ) ) {
update_option( 'alg_wc_ean_reset_settings', 'no' );
global $wpdb;
$deleted = $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'alg_wc_ean%'" );
if ( is_callable( array( 'WC_Admin_Settings', 'add_message' ) ) ) {
WC_Admin_Settings::add_message( sprintf( __( 'Settings reset: %d option(s) deleted.', 'ean-for-woocommerce' ), $deleted ) );
}
}
}
/**
* import_settings.
*
* @version 4.0.0
* @since 3.1.0
*
* @todo (dev) better data validation?
*/
function import_settings() {
if ( ! empty( $_FILES['alg_wc_ean_import_settings']['tmp_name'] ) ) {
$content = file_get_contents( $_FILES['alg_wc_ean_import_settings']['tmp_name'] );
$content = json_decode( $content, true );
if ( JSON_ERROR_NONE === json_last_error() ) {
$counter = 0;
foreach ( $content as $row ) {
if ( ! in_array( $row['option_name'], array( 'alg_wc_ean_version', 'alg_wc_ean_export_settings', 'alg_wc_ean_reset_settings' ) ) ) {
if ( update_option( $row['option_name'], $row['option_value'] ) ) {
$counter++;
}
}
}
if ( is_callable( array( 'WC_Admin_Settings', 'add_message' ) ) ) {
WC_Admin_Settings::add_message( sprintf( __( 'Settings imported: %d option(s) updated.', 'ean-for-woocommerce' ), $counter ) );
}
} elseif ( is_callable( array( 'WC_Admin_Settings', 'add_message' ) ) ) {
WC_Admin_Settings::add_message( sprintf( __( 'Import file error: %s', 'ean-for-woocommerce' ), json_last_error_msg() ) );
}
}
}
/**
* export_settings.
*
* @version 3.8.0
* @since 3.1.0
*
* @todo (dev) remove `length`?
* @todo (dev) recheck headers?
* @todo (dev) redirect page?
*/
function export_settings() {
if ( 'yes' === get_option( 'alg_wc_ean_export_settings', 'no' ) ) {
update_option( 'alg_wc_ean_export_settings', 'no' );
global $wpdb;
$content = $wpdb->get_results( "SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE 'alg_wc_ean%'" );
foreach ( $content as &$row ) {
$row->option_value = maybe_unserialize( $row->option_value );
}
$content = json_encode( $content );
$length = strlen( $content );
header( 'Content-Description: File Transfer' );
header( 'Content-Type: text/plain' );
header( 'Content-Disposition: attachment; filename=alg-wc-ean-settings.txt' );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Length: ' . $length );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Expires: 0' );
header( 'Pragma: public' );
echo $content;
exit;
}
}
}
endif;
return new Alg_WC_EAN_Manage_Settings();

View File

@@ -0,0 +1,100 @@
<?php
/**
* EAN for WooCommerce - Order Items Table Class
*
* @version 3.7.0
* @since 3.7.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Order_Items_Table' ) ) :
class Alg_WC_EAN_Order_Items_Table {
/**
* Constructor.
*
* @version 3.7.0
* @since 3.7.0
*/
function __construct() {
if (
'yes' === get_option( 'alg_wc_ean_order_items_table', 'no' ) ||
'yes' === get_option( 'alg_wc_ean_order_items_table_emails', get_option( 'alg_wc_ean_order_items_table', 'no' ) )
) {
add_action( 'woocommerce_order_item_meta_end', array( $this, 'add_to_order_item_meta_ean' ), 10, 4 );
add_action( 'woocommerce_email_before_order_table', array( $this, 'save_email_data' ), 10, 4 );
add_action( 'woocommerce_email_after_order_table', array( $this, 'reset_email_data' ), 10, 0 );
}
}
/**
* save_email_data.
*
* @version 3.7.0
* @since 3.1.0
*/
function save_email_data( $order, $sent_to_admin, $plain_text, $email ) {
$this->email = $email;
}
/**
* reset_email_data.
*
* @version 3.7.0
* @since 3.1.0
*/
function reset_email_data() {
$this->email = false;
}
/**
* add_to_order_item_meta_ean.
*
* @version 3.7.0
* @since 1.2.0
*/
function add_to_order_item_meta_ean( $item_id, $item, $order, $plain_text ) {
if ( false !== ( $ean = alg_wc_ean()->core->get_ean_from_order_item( $item ) ) ) {
// Do we need to display?
$do_display_in_emails = ( 'yes' === get_option( 'alg_wc_ean_order_items_table_emails', get_option( 'alg_wc_ean_order_items_table', 'no' ) ) );
$emails = get_option( 'alg_wc_ean_order_items_table_emails_list', array() );
$do_display_on_pages = ( 'yes' === get_option( 'alg_wc_ean_order_items_table', 'no' ) );
if ( $do_display_in_emails && empty( $emails ) && $do_display_on_pages ) {
// Display everywhere, no need to check further...
$do_display = true;
} else {
if ( empty( $this->email ) ) {
// "WooCommerce Email Customizer with Drag and Drop Email Builder" plugin by "Flycart Technologies LLP"
global $woo_email_arguments;
if ( ! empty( $woo_email_arguments['email'] ) ) {
$this->email = $woo_email_arguments['email'];
}
}
if ( ! empty( $this->email ) ) {
// It's an email...
$do_display = ( $do_display_in_emails ? ( empty( $emails ) || in_array( $this->email->id, $emails ) ) : false );
} else {
// It's a page, e.g., "Thank you"
$do_display = $do_display_on_pages;
}
}
// Display
if ( $do_display ) {
$templates = array_replace( array(
'html' => '<ul class="wc-item-meta"><li><span class="sku_wrapper ean_wrapper">EAN: <span class="ean">%ean%</span></span></li></ul>',
'plain_text' => '%new_line%- EAN: %ean%',
), get_option( 'alg_wc_ean_order_items_table_templates', array() ) );
echo str_replace( array( '%new_line%', '%ean%' ), array( "\n", $ean ), $templates[ ( ! $plain_text ? 'html' : 'plain_text' ) ] );
}
}
}
}
endif;
return new Alg_WC_EAN_Order_Items_Table();

View File

@@ -0,0 +1,94 @@
<?php
/**
* EAN for WooCommerce - Order Tools Class
*
* @version 3.9.0
* @since 3.9.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Order_Tools' ) ) :
class Alg_WC_EAN_Order_Tools {
/**
* Constructor.
*
* @version 3.9.0
* @since 3.9.0
*/
function __construct() {
add_action( 'alg_wc_ean_settings_saved', array( $this, 'orders_add' ) );
add_action( 'alg_wc_ean_settings_saved', array( $this, 'orders_delete' ) );
}
/**
* get_orders.
*
* @version 2.1.0
* @since 2.1.0
*
* @see https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query
*/
function get_orders() {
return wc_get_orders( array( 'limit' => -1, 'return' => 'ids' ) );
}
/**
* orders_delete.
*
* @version 2.9.0
* @since 2.1.0
*/
function orders_delete() {
if ( 'yes' === get_option( 'alg_wc_ean_tool_orders_delete', 'no' ) ) {
update_option( 'alg_wc_ean_tool_orders_delete', 'no' );
if ( current_user_can( 'manage_woocommerce' ) ) {
$count = 0;
foreach ( $this->get_orders() as $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order ) {
continue;
}
foreach ( $order->get_items() as $item_id => $item ) {
if ( wc_delete_order_item_meta( $item_id, alg_wc_ean()->core->ean_key ) ) {
$count++;
}
}
}
if ( method_exists( 'WC_Admin_Settings', 'add_message' ) ) {
WC_Admin_Settings::add_message( sprintf( __( 'EAN deleted for %s order items.', 'ean-for-woocommerce' ), $count ) );
}
}
}
}
/**
* orders_add.
*
* @version 2.9.0
* @since 2.1.0
*/
function orders_add() {
if ( 'yes' === get_option( 'alg_wc_ean_tool_orders_add', 'no' ) ) {
update_option( 'alg_wc_ean_tool_orders_add', 'no' );
if ( current_user_can( 'manage_woocommerce' ) ) {
$count = 0;
foreach ( $this->get_orders() as $order_id ) {
$count += alg_wc_ean()->core->orders->add_ean_to_order_items_meta( $order_id );
}
if ( method_exists( 'WC_Admin_Settings', 'add_message' ) ) {
WC_Admin_Settings::add_message( sprintf( __( 'EAN added for %s order items.', 'ean-for-woocommerce' ), $count ) );
}
}
}
}
}
endif;
return new Alg_WC_EAN_Order_Tools();

View File

@@ -0,0 +1,89 @@
<?php
/**
* EAN for WooCommerce - Orders Class
*
* @version 3.7.0
* @since 2.1.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Orders' ) ) :
class Alg_WC_EAN_Orders {
/**
* Constructor.
*
* @version 3.7.0
* @since 2.1.0
*
* @todo (feature) option to add it to `woocommerce_hidden_order_itemmeta`
*/
function __construct() {
// Orders items meta
if ( 'yes' === get_option( 'alg_wc_ean_order_items_meta', 'no' ) ) {
add_action( 'woocommerce_checkout_order_processed', array( $this, 'add_ean_to_order_items_meta' ), PHP_INT_MAX, 1 );
}
// Admin new order (AJAX)
if ( 'yes' === get_option( 'alg_wc_ean_order_items_meta_admin', 'no' ) ) {
add_action( 'woocommerce_new_order_item', array( $this, 'new_order_item_ajax' ), PHP_INT_MAX, 2 );
}
}
/**
* new_order_item_ajax.
*
* @version 2.1.0
* @since 2.1.0
*
* @todo (fix) EAN meta is not displayed until order page is reloaded
*/
function new_order_item_ajax( $item_id, $item ) {
if (
defined( 'DOING_AJAX' ) && DOING_AJAX &&
'WC_Order_Item_Product' === get_class( $item ) &&
'' === wc_get_order_item_meta( $item_id, alg_wc_ean()->core->ean_key ) &&
( $product_id = ( ! empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'] ) ) &&
'' !== ( $ean = alg_wc_ean()->core->get_ean( $product_id, true ) )
) {
wc_update_order_item_meta( $item_id, alg_wc_ean()->core->ean_key, $ean );
}
}
/**
* add_ean_to_order_items_meta.
*
* @version 2.1.0
* @since 2.1.0
*
* @todo (feature) editable field?
* @todo (dev) `( $do_overwrite || '' === wc_get_order_item_meta( $item_id, alg_wc_ean()->core->ean_key, true )`
*/
function add_ean_to_order_items_meta( $order_id ) {
$count = 0;
$order = wc_get_order( $order_id );
if ( $order ) {
foreach ( $order->get_items() as $item_id => $item ) {
if (
0 != ( $product_id = ( ! empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'] ) ) &&
'' !== ( $ean = alg_wc_ean()->core->get_ean( $product_id, true ) )
) {
wc_update_order_item_meta( $item_id, alg_wc_ean()->core->ean_key, $ean );
$count++;
}
}
}
return $count;
}
}
endif;
return new Alg_WC_EAN_Orders();

View File

@@ -0,0 +1,900 @@
<?php
/**
* EAN for WooCommerce - Product Tools Class
*
* @version 4.8.3
* @since 2.1.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Product_Tools' ) ) :
class Alg_WC_EAN_Product_Tools {
/**
* Constructor.
*
* @version 4.1.2
* @since 2.1.0
*
* @todo (dev) split into more files/classes, e.g., `class-alg-wc-ean-crons.php`?
* @todo (feature) Automatic actions: `updated_postmeta`?
* @todo (dev) Automatic actions: `woocommerce_after_product_object_save`?
*/
function __construct() {
// Products Tools
add_action( 'alg_wc_ean_settings_saved', array( $this, 'products_delete' ) );
add_action( 'alg_wc_ean_settings_saved', array( $this, 'products_create' ) );
// Automatic actions
add_action( 'wp_insert_post', array( $this, 'product_on_insert_post' ), PHP_INT_MAX, 3 );
// Periodic action
if ( '' !== get_option( 'alg_wc_ean_products_periodic_action', '' ) ) {
add_action( 'init', array( $this, 'schedule_products_periodic_action' ) );
add_action( 'alg_wc_ean_products_periodic_action', array( $this, 'process_products_periodic_action' ) );
} else {
add_action( 'init', array( $this, 'unschedule_products_periodic_action' ) );
}
// "Products > Bulk actions"
add_filter( 'bulk_actions-edit-product', array( $this, 'add_product_bulk_actions' ) );
add_filter( 'handle_bulk_actions-edit-product', array( $this, 'handle_product_bulk_actions' ), 10, 3 );
add_action( 'admin_footer', array( $this, 'bulk_actions_confirmation_js' ) );
// Assign from the list: Reuse deleted
add_action( 'before_delete_post', array( $this, 'reuse_deleted' ), 10, 2 );
}
/**
* bulk_actions_confirmation_js.
*
* @version 4.1.2
* @since 4.1.2
*
* @todo (dev) load only when needed
* @todo (dev) use `admin_enqueue_scripts`
*/
function bulk_actions_confirmation_js() {
$actions = get_option( 'alg_wc_ean_product_bulk_actions', array( 'alg_wc_ean_delete', 'alg_wc_ean_generate' ) );
$confirm = get_option( 'alg_wc_ean_product_bulk_actions_confirm', array( 'alg_wc_ean_delete' ) );
$confirm_ids = array_intersect( $actions, $confirm );
if ( ! empty( $confirm_ids ) ) {
?><script>
const confirm_ids = <?php echo "['" . implode( "','", $confirm_ids ) . "']"; ?>;
jQuery( '#doaction' ).on( 'click', function () {
if ( -1 != confirm_ids.indexOf( jQuery( 'select[name="action"]' ).val() ) ) {
if ( ! confirm( "<?php echo esc_html__( 'Are you sure?', 'ean-for-woocommerce' ); ?>" ) ) {
return false;
}
}
} );
</script><?php
}
}
/**
* reuse_deleted.
*
* @version 3.7.0
* @since 3.7.0
*
* @todo (dev) `product_variation` + `alg_wc_ean_tool_product_variable`?
* @todo (feature) add option to add to the end of the list (i.e., not to the beginning of the list, as it is now)
*/
function reuse_deleted( $postid, $post ) {
$assign_list_settings = get_option( 'alg_wc_ean_tool_product_assign_list_settings', array() );
if (
! empty( $assign_list_settings['reuse_deleted'] ) && 'yes' === $assign_list_settings['reuse_deleted'] &&
in_array( $post->post_type, array( 'product', 'product_variation' ) ) &&
'' !== ( $ean = get_post_meta( $postid, alg_wc_ean()->core->ean_key, true ) )
) {
$data = ( '' !== ( $data = get_option( 'alg_wc_ean_tool_product_assign_list', '' ) ) ? array_map( 'trim', explode( PHP_EOL, $data ) ) : array() );
update_option( 'alg_wc_ean_tool_product_assign_list', implode( PHP_EOL, array_merge( array( $ean ), $data ) ) );
}
}
/**
* process_products_periodic_action.
*
* @version 2.9.0
* @since 2.9.0
*
* @todo (dev) log
*/
function process_products_periodic_action( $args ) {
if ( '' !== ( $action = get_option( 'alg_wc_ean_products_periodic_action', '' ) ) ) {
$this->process_action_for_all_products( $action );
}
}
/**
* unschedule_products_periodic_action.
*
* @version 2.9.0
* @since 2.9.0
*/
function unschedule_products_periodic_action() {
if ( function_exists( 'as_unschedule_all_actions' ) ) {
as_unschedule_all_actions( 'alg_wc_ean_products_periodic_action' );
}
}
/**
* schedule_products_periodic_action.
*
* @version 2.9.0
* @since 2.9.0
*/
function schedule_products_periodic_action() {
if (
function_exists( 'as_has_scheduled_action' ) &&
( $interval_in_seconds = get_option( 'alg_wc_ean_products_periodic_action_interval', 3600 ) ) &&
false === as_has_scheduled_action( 'alg_wc_ean_products_periodic_action', array( $interval_in_seconds ) )
) {
as_unschedule_all_actions( 'alg_wc_ean_products_periodic_action' );
as_schedule_recurring_action( time(), $interval_in_seconds, 'alg_wc_ean_products_periodic_action', array( $interval_in_seconds ) );
}
}
/**
* handle_product_bulk_actions.
*
* @version 4.5.0
* @since 2.7.0
*
* @todo (feature) all other actions, e.g., "Copy EAN from SKU", etc.
* @todo (dev) notices
* @todo (dev) merge with `products_create()`?
*/
function handle_product_bulk_actions( $redirect_to, $action, $post_ids ) {
if ( in_array( $action, array( 'alg_wc_ean_generate', 'alg_wc_ean_delete' ) ) ) {
$data = ( 'alg_wc_ean_generate' === $action ? $this->get_generate_data() : false );
$count = 0;
foreach ( $post_ids as $post_id ) {
$product = wc_get_product( $post_id );
if ( $product->is_type( 'variable' ) ) {
$variations = array_keys( get_children( array( 'post_parent' => $post_id, 'posts_per_page' => -1, 'post_type' => 'product_variation' ), 'ARRAY_N' ) );
switch ( get_option( 'alg_wc_ean_tool_product_variable', 'all' ) ) {
case 'variations_only':
$product_ids = $variations;
break;
case 'variable_only':
$product_ids = array( $post_id );
break;
default: // 'all'
$product_ids = array_merge( array( $post_id ), $variations );
break;
}
} else {
$product_ids = array( $post_id );
}
foreach ( $product_ids as $product_id ) {
switch ( $action ) {
case 'alg_wc_ean_generate':
$result = (
'' === get_post_meta( $product_id, alg_wc_ean()->core->ean_key, true ) &&
'' !== ( $ean = $this->generate_ean( $product_id, $data ) ) &&
alg_wc_ean()->core->set_ean( $product_id, $ean )
);
if ( $result && '' !== $data['product_attribute'] ) {
$this->add_product_attribute( $product_id, $ean, $data['product_attribute'] );
}
break;
case 'alg_wc_ean_delete':
$result = delete_post_meta( $product_id, alg_wc_ean()->core->ean_key );
break;
}
if ( $result ) {
$count++;
}
}
}
}
return $redirect_to;
}
/**
* add_product_bulk_actions.
*
* @version 2.9.0
* @since 2.7.0
*/
function add_product_bulk_actions( $actions ) {
return array_merge( $actions, array_intersect_key( array(
'alg_wc_ean_generate' => __( 'Generate EAN', 'ean-for-woocommerce' ),
'alg_wc_ean_delete' => __( 'Delete EAN', 'ean-for-woocommerce' ),
), array_flip( get_option( 'alg_wc_ean_product_bulk_actions', array( 'alg_wc_ean_delete', 'alg_wc_ean_generate' ) ) ) ) );
}
/**
* get_products.
*
* @version 4.7.2
* @since 2.1.0
*
* @see https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
*
* @todo (dev) `meta_query`: `ean` not empty
* @todo (feature) optional: `meta_query`: `ean` not empty
*/
function get_products( $action = false ) {
// Get product types
$product_types = array_merge( array_keys( wc_get_product_types() ), array( 'variation' ) );
if ( 'all' !== ( $variable_products = get_option( 'alg_wc_ean_tool_product_variable', 'all' ) ) ) {
$unset = ( 'variations_only' === $variable_products ? 'variable' : 'variation' );
if ( false !== ( $key = array_search( $unset, $product_types ) ) ) {
unset( $product_types[ $key ] );
}
}
// Query args
$args = array(
'limit' => -1,
'return' => 'ids',
'orderby' => 'ID',
'order' => 'ASC',
'type' => $product_types,
);
// Product options
$product_options = false;
switch ( $action ) {
case 'assign_list':
$product_options = get_option( 'alg_wc_ean_tool_product_assign_list_settings', array() );
break;
}
if ( $product_options ) {
foreach ( array( 'product_cat' => 'category' ) as $taxonomy => $arg ) {
$terms = ( isset( $product_options[ $taxonomy ] ) ? $product_options[ $taxonomy ] : array() );
if ( ! empty( $terms ) ) {
$args[ $arg ] = array_map( array( $this, "get_{$taxonomy}_slug" ), $terms );
}
}
}
// Fix variations `category`
if ( ( $do_fix_variations = ( 'variable_only' !== $variable_products && ! empty( $args['category'] ) ) ) ) {
$do_remove_variable = false;
if ( 'variations_only' === $variable_products ) {
// Temporarily get `variable` products
$args['type'][] = 'variable';
$do_remove_variable = true;
}
}
// Query
$products = wc_get_products( $args );
// Fix variations `category`: Add variations
if ( $do_fix_variations ) {
$_products = array();
foreach ( $products as $product_id ) {
$children = ( 'variable' !== WC_Product_Factory::get_product_type( $product_id ) ? false :
array_keys( get_children( array(
'post_parent' => $product_id,
'posts_per_page' => -1,
'post_type' => 'product_variation',
), 'ARRAY_N' ) ) );
if ( ! empty( $children ) ) {
// Variable products
if ( ! $do_remove_variable ) {
$_products[] = $product_id; // only when `$variable_products` is set to `all` (i.e., not to `variations_only`)
}
$_products = array_merge( $_products, $children );
} else {
// Other (e.g., simple) products
$_products[] = $product_id;
}
}
$products = $_products;
sort( $products );
}
return $products;
}
/**
* get_product_cat_slug.
*
* @version 3.0.0
* @since 3.0.0
*/
function get_product_cat_slug( $term_id ) {
$term = get_term( $term_id, 'product_cat' );
return ( $term && ! is_wp_error( $term ) ? $term->slug : '' );
}
/**
* products_delete.
*
* @version 2.1.0
* @since 2.1.0
*
* @todo (dev) delete `product_attribute` as well
* @todo (dev) delete directly with SQL from the `meta` table: `$counter = $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_key = '" . alg_wc_ean()->core->ean_key . "'" );`
* @todo (dev) better notice(s)?
*/
function products_delete() {
if ( 'yes' === get_option( 'alg_wc_ean_tool_delete_product_meta', 'no' ) ) {
update_option( 'alg_wc_ean_tool_delete_product_meta', 'no' );
if ( current_user_can( 'manage_woocommerce' ) ) {
$count = 0;
foreach ( $this->get_products() as $product_id ) {
if ( delete_post_meta( $product_id, alg_wc_ean()->core->ean_key ) ) {
$count++;
}
}
if ( method_exists( 'WC_Admin_Settings', 'add_message' ) ) {
WC_Admin_Settings::add_message( sprintf( __( 'EAN deleted for %s products.', 'ean-for-woocommerce' ), $count ) );
}
}
}
}
/**
* is_valid_product.
*
* @version 3.0.0
* @since 3.0.0
*/
function is_valid_product( $post_id, $action ) {
$product_options = false;
switch ( $action ) {
case 'assign_list':
$product_options = get_option( 'alg_wc_ean_tool_product_assign_list_settings', array() );
break;
}
if ( $product_options ) {
foreach ( array( 'product_cat' => 'category' ) as $taxonomy => $arg ) {
$terms = ( isset( $product_options[ $taxonomy ] ) ? $product_options[ $taxonomy ] : array() );
if ( ! empty( $terms ) && ! has_term( $terms, $taxonomy, $post_id ) ) {
return false;
}
}
}
return true;
}
/**
* product_on_insert_post.
*
* @version 4.8.3
* @since 2.2.8
*
* @todo (dev) merge with `products_create()`?
* @todo (dev) stop on first `update_post_meta`?
*/
function product_on_insert_post( $post_id, $post, $update ) {
$action = get_option( ( $update ? 'alg_wc_ean_tool_product_action_on_update' : 'alg_wc_ean_tool_product_action_on_new' ), '' );
if (
! empty( $action ) &&
in_array( $post->post_type, array( 'product', 'product_variation' ) ) &&
$this->is_valid_product( $post_id, $action )
) {
$product = wc_get_product( $post_id );
if ( 'all' !== ( $variable_products = get_option( 'alg_wc_ean_tool_product_variable', 'all' ) ) ) {
if (
( $product->is_type( 'variable' ) && 'variations_only' === $variable_products ) ||
( $product->is_type( 'variation' ) && 'variable_only' === $variable_products )
) {
return;
}
}
if ( '' === ( $current_ean = get_post_meta( $post_id, alg_wc_ean()->core->ean_key, true ) ) ) {
// Action: Generate, Copy from SKU/ID/meta, Assign from the list
$ean = '';
switch ( $action ) {
case 'generate':
$data = $this->get_generate_data();
$ean = $this->generate_ean( $post_id, $data );
break;
case 'copy_sku':
$ean = ( $product ? $product->get_sku() : get_post_meta( $post_id, '_sku', true ) );
break;
case 'copy_id':
$ean = $post_id;
break;
case 'copy_meta':
$data = array_replace( array( 'key' => '', 'sub_key' => '' ), get_option( 'alg_wc_ean_tool_product_copy_meta', array() ) );
if ( '' !== $data['key'] ) {
$ean = get_post_meta( $post_id, $data['key'], true );
if ( '' !== $data['sub_key'] ) {
$ean = ( isset( $ean[ $data['sub_key'] ] ) ? $ean[ $data['sub_key'] ] : '' );
}
}
break;
case 'copy_attr':
$data = get_option( 'alg_wc_ean_tool_product_copy_attr', array() );
if ( isset( $data['product_attribute'] ) && 'alg_wc_ean_product_attribute_custom' === $data['product_attribute'] ) {
$data['product_attribute'] = ( isset( $data['product_attribute_custom'] ) ? $data['product_attribute_custom'] : '' );
}
if ( isset( $data['product_attribute'] ) && '' !== $data['product_attribute'] ) {
$ean = ( $product ? $product->get_attribute( $data['product_attribute'] ) : get_post_meta( $post_id, 'attribute_' . $data['product_attribute'], true ) );
}
break;
case 'assign_list':
$data = get_option( 'alg_wc_ean_tool_product_assign_list', '' );
if ( '' !== $data ) {
$data = array_map( 'trim', explode( PHP_EOL, $data ) );
$ean = array_shift( $data );
update_option( 'alg_wc_ean_tool_product_assign_list', ( empty( $data ) ? '' : implode( PHP_EOL, $data ) ) );
}
break;
}
if ( '' !== $ean ) {
alg_wc_ean()->core->set_ean( $post_id, $ean );
if ( 'generate' === $action && '' !== $data['product_attribute'] ) {
$this->add_product_attribute( $post_id, $ean, $data['product_attribute'] );
}
// Prevent the new EAN from being overwritten by the variation's `input` field on the product edit page
if ( 'product_variation' === $post->post_type && isset( alg_wc_ean()->core->edit ) ) {
remove_action( 'woocommerce_save_product_variation', array( alg_wc_ean()->core->edit, 'save_ean_input_variation' ), 10 );
}
}
} else {
// Action: Copy to product SKU/attribute
switch ( $action ) {
case 'copy_to_sku':
update_post_meta( $post_id, '_sku', $current_ean );
break;
case 'copy_to_meta':
$data = get_option( 'alg_wc_ean_tool_product_copy_to_meta', array() );
$data['keys'] = ( isset( $data['key'] ) && '' !== $data['key'] ? explode( ',', $data['key'] ) : array() );
$data['sub_keys'] = ( isset( $data['sub_key'] ) && '' !== $data['sub_key'] ? explode( ',', $data['sub_key'] ) : array() );
foreach ( $data['keys'] as $i => $key ) {
if ( '' === $key ) {
continue;
}
if ( isset( $data['sub_keys'][ $i ] ) && '' !== $data['sub_keys'][ $i ] ) {
if ( '' === ( $_value = get_post_meta( $post_id, $key, true ) ) ) {
$_value = array();
} elseif ( ! is_array( $_value ) ) {
continue;
}
$_value[ $data['sub_keys'][ $i ] ] = $current_ean;
update_post_meta( $post_id, $key, $_value );
} else {
update_post_meta( $post_id, $key, $current_ean );
}
}
break;
case 'copy_to_attr':
$data = get_option( 'alg_wc_ean_tool_product_copy_to_attr', array() );
if ( isset( $data['product_attribute'] ) && '' !== $data['product_attribute'] ) {
$this->add_product_attribute( $post_id, $current_ean, $data['product_attribute'] );
}
break;
}
}
}
}
/**
* process_action_for_all_products.
*
* @version 4.8.3
* @since 2.9.0
*
* @todo (dev) Copy to: do NOT overwrite?
* @todo (dev) `array_shift()` vs `array_reverse()` + `array_pop()`?
*/
function process_action_for_all_products( $action ) {
// Prepare (and validate) data
switch ( $action ) {
case 'generate':
$data = $this->get_generate_data();
break;
case 'copy_meta':
$data = array_replace( array( 'key' => '', 'sub_key' => '' ), get_option( 'alg_wc_ean_tool_product_copy_meta', array() ) );
if ( '' === $data['key'] ) {
return array( 'result' => false, 'message' => __( 'Please set the "Meta key" option.', 'ean-for-woocommerce' ) );
}
break;
case 'copy_attr':
$data = get_option( 'alg_wc_ean_tool_product_copy_attr', array() );
if ( ! isset( $data['product_attribute'] ) || '' === $data['product_attribute'] ) {
return array( 'result' => false, 'message' => __( 'Please set the "Product attribute" option.', 'ean-for-woocommerce' ) );
}
if ( 'alg_wc_ean_product_attribute_custom' === $data['product_attribute'] ) {
if ( ! isset( $data['product_attribute_custom'] ) || '' === $data['product_attribute_custom'] ) {
return array( 'result' => false, 'message' => __( 'Please set the "Custom product attribute" option.', 'ean-for-woocommerce' ) );
}
$data['product_attribute'] = $data['product_attribute_custom'];
}
break;
case 'assign_list':
$data = get_option( 'alg_wc_ean_tool_product_assign_list', '' );
if ( '' === $data ) {
return array( 'result' => false, 'message' => __( 'Please set the "List" option.', 'ean-for-woocommerce' ) );
} else {
$data = array_map( 'trim', explode( PHP_EOL, $data ) );
}
break;
case 'copy_to_meta':
$data = get_option( 'alg_wc_ean_tool_product_copy_to_meta', array() );
$data['keys'] = ( isset( $data['key'] ) && '' !== $data['key'] ? explode( ',', $data['key'] ) : array() );
$data['sub_keys'] = ( isset( $data['sub_key'] ) && '' !== $data['sub_key'] ? explode( ',', $data['sub_key'] ) : array() );
if ( empty( $data['keys'] ) ) {
return array( 'result' => false, 'message' => __( 'Please set the "Meta key" option.', 'ean-for-woocommerce' ) );
}
break;
case 'copy_to_attr':
$data = get_option( 'alg_wc_ean_tool_product_copy_to_attr', array() );
$data['product_attribute'] = ( isset( $data['product_attribute'] ) ? $data['product_attribute'] : '' );
break;
}
// Product loop
$products = $this->get_products( $action );
$total = count( $products );
$count = 0;
foreach ( $products as $product_id ) {
$current_ean = get_post_meta( $product_id, alg_wc_ean()->core->ean_key, true );
// Action: Get stats
if ( 'get_stats' === $action ) {
if ( '' === $current_ean ) {
$count++;
}
continue;
}
// Action: Copy to product SKU/meta/attribute
if ( 'copy_to_sku' === $action ) {
if ( '' !== $current_ean ) {
if ( update_post_meta( $product_id, '_sku', $current_ean ) ) {
$count++;
}
}
continue;
}
if ( 'copy_to_meta' === $action ) {
if ( '' !== $current_ean ) {
foreach ( $data['keys'] as $i => $key ) {
if ( '' === $key ) {
continue;
}
if ( isset( $data['sub_keys'][ $i ] ) && '' !== $data['sub_keys'][ $i ] ) {
if ( '' === ( $_value = get_post_meta( $product_id, $key, true ) ) ) {
$_value = array();
} elseif ( ! is_array( $_value ) ) {
continue;
}
$_value[ $data['sub_keys'][ $i ] ] = $current_ean;
if ( update_post_meta( $product_id, $key, $_value ) ) {
$count++;
}
} else {
if ( update_post_meta( $product_id, $key, $current_ean ) ) {
$count++;
}
}
}
}
continue;
}
if ( 'copy_to_attr' === $action && '' !== $data['product_attribute'] ) {
if ( '' !== $current_ean ) {
if ( $this->add_product_attribute( $product_id, $current_ean, $data['product_attribute'] ) ) {
$count++;
}
}
continue;
}
// Action: Generate, Copy from SKU/ID/meta, Assign from the list
if ( '' !== $current_ean ) {
continue;
}
$ean = '';
switch ( $action ) {
case 'generate':
$ean = $this->generate_ean( $product_id, $data );
break;
case 'copy_sku':
$ean = ( ( $product = wc_get_product( $product_id ) ) ? $product->get_sku() : get_post_meta( $product_id, '_sku', true ) );
break;
case 'copy_id':
$ean = $product_id;
break;
case 'copy_meta':
$ean = get_post_meta( $product_id, $data['key'], true );
if ( '' !== $data['sub_key'] ) {
$ean = ( isset( $ean[ $data['sub_key'] ] ) ? $ean[ $data['sub_key'] ] : '' );
}
break;
case 'copy_attr':
$ean = ( ( $product = wc_get_product( $product_id ) ) ? $product->get_attribute( $data['product_attribute'] ) : get_post_meta( $product_id, 'attribute_' . $data['product_attribute'], true ) );
break;
case 'assign_list':
$ean = array_shift( $data );
break;
}
if ( '' !== $ean && alg_wc_ean()->core->set_ean( $product_id, $ean ) ) {
if ( 'generate' === $action && '' !== $data['product_attribute'] ) {
$this->add_product_attribute( $product_id, $ean, $data['product_attribute'] );
}
$count++;
}
if ( 'assign_list' === $action && empty( $data ) ) {
break;
}
}
if ( 'assign_list' === $action ) {
update_option( 'alg_wc_ean_tool_product_assign_list', ( empty( $data ) ? '' : implode( PHP_EOL, $data ) ) );
}
switch ( $action ) {
case 'generate':
$message = __( 'EAN generated for %s products (%s total products).', 'ean-for-woocommerce' );
break;
case 'assign_list':
$message = __( 'EAN assigned for %s products (%s total products).', 'ean-for-woocommerce' );
break;
case 'get_stats':
$message = __( '%s products without EAN (%s total products).', 'ean-for-woocommerce' );
break;
default:
$message = __( 'EAN copied for %s products (%s total products).', 'ean-for-woocommerce' );
}
return array( 'result' => true, 'message' => sprintf( $message, $count, $total ) );
}
/**
* products_create.
*
* @version 4.4.2
* @since 2.1.0
*
* @todo (dev) message: "success/error" (i.e., check `$response['result']`)
* @todo (feature) per individual product (JS or AJAX?)
* @todo (dev) better notice(s)?
*/
function products_create() {
$tools = array_replace( array(
'generate' => 'no',
'copy_sku' => 'no',
'copy_id' => 'no',
'copy_meta' => 'no',
'copy_attr' => 'no',
'assign_list' => 'no',
'get_stats' => 'no',
'copy_to_sku' => 'no',
'copy_to_meta' => 'no',
'copy_to_attr' => 'no',
), get_option( 'alg_wc_ean_tool_product', array() ) );
if ( in_array( 'yes', $tools ) ) {
delete_option( 'alg_wc_ean_tool_product' );
if ( current_user_can( 'manage_woocommerce' ) ) {
foreach ( $tools as $tool => $is_enabled ) {
if ( 'yes' === $is_enabled ) {
$action = $tool;
break;
}
}
$response = $this->process_action_for_all_products( $action );
if ( ! empty( $response['message'] ) && method_exists( 'WC_Admin_Settings', 'add_message' ) ) {
WC_Admin_Settings::add_message( $response['message'] );
}
}
}
}
/**
* add_product_attribute.
*
* @version 3.9.0
* @since 3.7.2
*
* @todo (feature) local (i.e., per product; non-taxonomy) product attribute
* @todo (dev) use `$product->set_attributes()` instead of `update_post_meta( $product_id, '_product_attributes', $product_attributes )`
*/
function add_product_attribute( $product_id, $ean, $taxonomy ) {
wp_set_object_terms( $product_id, $ean, $taxonomy );
$product_attributes = get_post_meta( $product_id, '_product_attributes', true );
if ( empty( $product_attributes ) ) {
$product_attributes = array();
}
$product_attributes[ $taxonomy ] = array(
'name' => $taxonomy,
'value' => $ean,
'is_visible' => 1,
'is_variation' => 0,
'is_taxonomy' => 1,
);
return update_post_meta( $product_id, '_product_attributes', $product_attributes );
}
/**
* get_generate_data.
*
* @version 3.9.0
* @since 2.2.8
*
* @todo (dev) `ISBN13`, `JAN`
* @todo (fix) `UPCA`: 1+5+5+1 (https://www.cognex.com/resources/symbologies/1-d-linear-barcodes/upc-a-barcodes)
* @todo (dev) move to a separate class/file, e.g., `class-alg-wc-ean-generator.php`?
*/
function get_generate_data() {
$res = array();
$default_data = array(
'type' => 'EAN13',
'prefix' => 200,
'prefix_to' => '',
'prefix_length' => 3,
'seed_prefix' => '',
'seed_method' => 'product_id',
'product_attribute' => '',
);
$data = array_replace( $default_data, get_option( 'alg_wc_ean_tool_product_generate', array() ) );
// Seed length
switch ( $data['type'] ) {
case 'EAN8':
$length = 8;
$res['prefix_length'] = $data['prefix_length'];
break;
case 'UPCA':
$length = 12;
$res['prefix_length'] = 3;
break;
default: // 'EAN13'
$length = 13;
$res['prefix_length'] = 3;
}
$res['seed_length'] = ( $length - $res['prefix_length'] - 1 );
// Seed prefix, i.e., "Manufacturer code"
$seed_prefix = ( strlen( $data['seed_prefix'] ) > $res['seed_length'] ? substr( $data['seed_prefix'], 0, $res['seed_length'] ) : $data['seed_prefix'] );
$res['seed_length'] -= strlen( $seed_prefix );
$res['seed_prefix'] = $seed_prefix;
// Prefix
if ( '' === $data['prefix'] ) {
$data['prefix'] = 0;
}
$res['is_rand_prefix'] = ( '' !== $data['prefix_to'] && $data['prefix'] != $data['prefix_to'] );
$res['prefix'] = ( $res['is_rand_prefix'] ?
array(
'from' => ( $data['prefix_to'] > $data['prefix'] ? $data['prefix'] : $data['prefix_to'] ),
'to' => ( $data['prefix_to'] > $data['prefix'] ? $data['prefix_to'] : $data['prefix'] ),
) :
str_pad( substr( $data['prefix'], 0, $res['prefix_length'] ), $res['prefix_length'], '0', STR_PAD_LEFT )
);
// Seed method, i.e., "Product code"
$res['seed_method'] = $data['seed_method'];
// Product attribute
$res['product_attribute'] = $data['product_attribute'];
return $res;
}
/**
* get_rand_prefix.
*
* @version 3.9.0
* @since 3.9.0
*/
function get_rand_prefix( $from, $to, $length ) {
return str_pad( substr( rand( $from, $to ), 0, $length ), $length, '0', STR_PAD_LEFT );
}
/**
* get_seed.
*
* @version 3.9.0
* @since 3.9.0
*
* @todo (dev) `counter`: (optional) max value?
*/
function get_seed( $method, $length, $args ) {
switch ( $method ) {
case 'product_id':
$seed = $args['product_id'];
break;
case 'counter':
global $wpdb;
$wpdb->query( 'START TRANSACTION' );
$seed = get_option( 'alg_wc_ean_tool_product_generate_seed_counter', 0 );
update_option( 'alg_wc_ean_tool_product_generate_seed_counter', ( $seed + 1 ) );
$wpdb->query( 'COMMIT' );
break;
}
return str_pad( substr( $seed, 0, $length ), $length, '0', STR_PAD_LEFT );
}
/**
* generate_ean.
*
* @version 4.0.0
* @since 2.2.8
*/
function generate_ean( $product_id, $data ) {
$prefix = ( $data['is_rand_prefix'] ? $this->get_rand_prefix( $data['prefix']['from'], $data['prefix']['to'], $data['prefix_length'] ) : $data['prefix'] );
$prefix = apply_filters( 'alg_wc_ean_product_tools_generate_ean_country_prefix', $prefix, $product_id );
$seed_prefix = apply_filters( 'alg_wc_ean_product_tools_generate_ean_seed_prefix', $data['seed_prefix'], $product_id );
$seed = $this->get_seed( $data['seed_method'], $data['seed_length'], array( 'product_id' => $product_id ) );
$seed = apply_filters( 'alg_wc_ean_product_tools_generate_ean_seed', $seed, $product_id );
$ean = $prefix . $seed_prefix . $seed;
return $ean . $this->get_checksum( $ean );
}
/**
* get_checksum.
*
* @version 2.2.7
* @since 2.2.5
*
* @see https://stackoverflow.com/questions/19890144/generate-valid-ean13-in-php
*/
function get_checksum( $code ) {
$flag = true;
$sum = 0;
for ( $i = strlen( $code ) - 1; $i >= 0; $i-- ) {
$sum += (int) $code[ $i ] * ( $flag ? 3 : 1 );
$flag = ! $flag;
}
return ( 10 - ( $sum % 10 ) ) % 10;
}
}
endif;
return new Alg_WC_EAN_Product_Tools();

View File

@@ -0,0 +1,194 @@
<?php
/**
* EAN for WooCommerce - REST API Class
*
* @version 4.8.2
* @since 3.7.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_REST_API' ) ) :
class Alg_WC_EAN_REST_API {
/**
* Constructor.
*
* @version 4.3.2
* @since 3.7.0
*
* @see https://woocommerce.github.io/woocommerce-rest-api-docs/
*
* @todo (feature) `create_product`
* @todo (feature) `create_order`
*/
function __construct() {
// Products
if ( 'yes' === get_option( 'alg_wc_ean_product_rest', 'no' ) ) {
add_filter( 'woocommerce_rest_prepare_product_object', array( $this, 'product_add_ean' ), PHP_INT_MAX, 3 );
add_filter( 'woocommerce_rest_prepare_product_variation_object', array( $this, 'product_add_ean' ), PHP_INT_MAX, 3 );
}
if ( 'yes' === get_option( 'alg_wc_ean_product_search_rest', 'no' ) ) {
add_filter( 'woocommerce_rest_product_object_query', array( $this, 'product_search' ), 10, 2 );
add_action( 'pre_get_posts', array( $this, 'product_variation_search' ) );
add_filter( 'woocommerce_rest_query_vars', array( $this, 'product_variation_search_var' ) );
}
// Orders
if ( 'yes' === get_option( 'alg_wc_ean_order_items_meta_rest', 'no' ) ) {
add_filter( 'woocommerce_rest_prepare_shop_order_object', array( $this, 'order_add_ean' ), PHP_INT_MAX, 3 );
}
if ( 'yes' === get_option( 'alg_wc_ean_order_items_meta_search_rest', 'no' ) ) {
add_filter( 'woocommerce_rest_orders_prepare_object_query', array( $this, 'order_search' ), 10, 2 );
}
}
/**
* product_variation_search_var.
*
* @version 4.3.0
* @since 4.3.0
*/
function product_variation_search_var( $vars ) {
$vars[] = 'alg_wc_ean_rest_api';
return $vars;
}
/**
* product_variation_search.
*
* @version 4.3.0
* @since 4.3.0
*/
function product_variation_search( $query ) {
if ( 'product_search' === $query->get( 'alg_wc_ean_rest_api' ) ) {
$query->set( 'post_type', array( 'product', 'product_variation' ) );
}
return $query;
}
/**
* product_search.
*
* @version 4.3.0
* @since 3.7.0
*
* @see https://github.com/woocommerce/woocommerce/blob/6.2.1/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-crud-controller.php#L340
*
* @todo (dev) use `meta_query` instead?
*/
function product_search( $args, $request ) {
if ( isset( $request['ean'] ) ) {
// Meta key/value
$args['meta_key'] = alg_wc_ean()->core->ean_key;
$args['meta_value'] = $request['ean'];
// For product variations
$args['alg_wc_ean_rest_api'] = 'product_search';
}
return $args;
}
/**
* product_add_ean.
*
* @version 4.4.5
* @since 2.9.0
*
* @see https://github.com/woocommerce/woocommerce/blob/6.2.1/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-products-v2-controller.php#L190
*/
function product_add_ean( $response, $product, $request ) {
$res_key = apply_filters( 'alg_wc_ean_rest_api_product_ean_key', 'ean', $response, $product, $request );
$response->data[ $res_key ] = alg_wc_ean()->core->get_ean( $product->get_id() );
return $response;
}
/**
* order_search.
*
* @version 3.7.0
* @since 3.7.0
*
* @see https://github.com/woocommerce/woocommerce/blob/6.2.1/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php#L524
*
* @todo (test) HPOS compatible?
* @todo (dev) fallback: get product(s) ID by EAN, then search order items by product ID
*/
function order_search( $args, $request ) {
if ( ! empty( $request['ean'] ) ) {
global $wpdb;
$order_ids = $wpdb->get_col(
$wpdb->prepare(
"SELECT order_id
FROM {$wpdb->prefix}woocommerce_order_items
WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '%s' AND meta_value = %s )
AND order_item_type = 'line_item'",
alg_wc_ean()->core->ean_key,
$request['ean']
)
);
// Force WP_Query return empty if don't found any order.
$order_ids = ! empty( $order_ids ) ? $order_ids : array( 0 );
$args['post__in'] = $order_ids;
}
return $args;
}
/**
* order_add_ean.
*
* @version 4.8.2
* @since 2.8.0
*
* @see https://github.com/woocommerce/woocommerce/blob/6.2.1/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-orders-v2-controller.php#L420
*/
function order_add_ean( $response, $order, $request ) {
if ( empty( $response->data['line_items'] ) ) {
return $response;
}
$res_key = apply_filters( 'alg_wc_ean_rest_api_order_ean_key', 'ean', $response, $order, $request );
foreach ( $response->data['line_items'] as $item_key => &$item ) {
$is_in_meta = false;
// Item meta
if ( ! empty( $item['meta_data'] ) ) {
foreach ( $item['meta_data'] as $meta_data ) {
if ( isset( $meta_data['key'], $meta_data['value'] ) && alg_wc_ean()->core->ean_key === $meta_data['key'] ) {
$item[ $res_key ] = $meta_data['value'];
$is_in_meta = true;
break;
}
}
}
// Product meta (fallback)
if ( ! $is_in_meta && isset( $item['product_id'] ) ) {
$product_id = ( ! empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'] );
if ( '' !== ( $ean = alg_wc_ean()->core->get_ean( $product_id ) ) ) {
$item[ $res_key ] = $ean;
}
}
}
return $response;
}
}
endif;
return new Alg_WC_EAN_REST_API();

View File

@@ -0,0 +1,298 @@
<?php
/**
* EAN for WooCommerce - Search Class
*
* @version 4.7.6
* @since 2.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Search' ) ) :
class Alg_WC_EAN_Search {
/**
* Constructor.
*
* @version 4.7.6
* @since 2.0.0
*
* @todo (dev) [!] replace `( ! is_admin() )` with `( ! is_admin() || wp_doing_ajax() )` (similar in "extra fields")?
* @todo (dev) Flatsome to `class-alg-wc-ean-compatibility.php`?
* @todo (dev) remove `! is_admin()` and `is_admin()`?
* @todo (dev) `alg_wc_ean_frontend_search_ajax_flatsome`: better solution?
* @todo (dev) search by EAN in "New Order"?
* @todo (dev) make `alg_wc_ean_backend_search_ajax` independent from `alg_wc_ean_backend_search`?
* @todo (dev) make `alg_wc_ean_frontend_search_ajax_flatsome` independent from `alg_wc_ean_frontend_search`?
*/
function __construct() {
if ( ! is_admin() ) {
// Frontend
if ( 'yes' === get_option( 'alg_wc_ean_frontend_search', 'yes' ) ) {
add_action( 'pre_get_posts', array( $this, 'search' ) );
}
} else {
// Backend
if ( 'yes' === get_option( 'alg_wc_ean_backend_search', 'yes' ) ) {
add_action( 'pre_get_posts', array( $this, 'search_backend' ) );
if ( 'yes' === get_option( 'alg_wc_ean_backend_search_ajax', 'yes' ) ) {
add_filter( 'woocommerce_json_search_found_products', array( $this, 'json_search_found_products' ) );
}
}
}
// "Flatsome" theme
if ( 'yes' === get_option( 'alg_wc_ean_frontend_search', 'yes' ) && 'yes' === get_option( 'alg_wc_ean_frontend_search_ajax_flatsome', 'no' ) ) {
add_filter( 'theme_mod_search_by_sku', array( $this, 'flatsome_search_ajax_mod' ), PHP_INT_MAX );
add_filter( 'flatsome_ajax_search_function', array( $this, 'flatsome_search_ajax_func' ), PHP_INT_MAX, 4 );
}
}
/**
* flatsome_search_ajax_mod.
*
* @version 2.1.0
* @since 2.1.0
*/
function flatsome_search_ajax_mod( $value ) {
$this->flatsome_theme_mod_search_by_sku = $value;
return 1;
}
/**
* flatsome_search_ajax.
*
* @version 2.4.2
* @since 2.1.0
*/
function flatsome_search_ajax( $search_query, $args, $defaults ) {
if ( ! $this->flatsome_theme_mod_search_by_sku ) {
$args['meta_query'][0]['key'] = alg_wc_ean()->core->ean_key;
$args['meta_query'][0]['compare'] = 'LIKE';
} else {
$args['meta_query'][] = array(
'key' => alg_wc_ean()->core->ean_key,
'value' => $args['meta_query'][0]['value'],
'compare' => 'LIKE',
);
$args['meta_query']['relation'] = 'OR';
}
return get_posts( $args );
}
/**
* flatsome_search_ajax_func.
*
* @version 2.1.0
* @since 2.1.0
*/
function flatsome_search_ajax_func( $func, $search_query, $args, $defaults ) {
return ( ! empty( $args['meta_query'][0]['key'] ) && '_sku' === $args['meta_query'][0]['key'] ? 'alg_wc_ean_flatsome_search_ajax' : $func );
}
/**
* search_backend.
*
* @version 4.7.6
* @since 1.0.0
*/
function search_backend( $query ) {
self::_search_backend( $query, alg_wc_ean()->core->ean_key, $this );
}
/**
* _search_backend.
*
* @version 4.7.6
* @since 4.7.6
*
* @todo (dev) rewrite?
*/
static function _search_backend( $query, $key, $obj ) {
if (
$query->is_main_query() &&
isset( $query->query['post_type'] ) && in_array( 'product', (array) $query->query['post_type'] ) &&
apply_filters( 'alg_wc_ean_search_backend', true, $query, $key )
) {
// Check search term
$search_term = isset( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
if ( empty( $search_term ) ) {
return;
}
// Clone query, etc.
$new_query = clone( $query );
$new_query->query_vars['s'] = '';
$old_product_in = $query->query_vars['post__in'];
// Unset `post__in`
unset( $new_query->query['post__in'] );
unset( $new_query->query_vars['post__in'] );
// Set `meta_query`
$new_meta_query = array(
'key' => $key,
'value' => $search_term,
'compare' => 'LIKE',
);
$old_meta_query = ( isset( $query->query_vars['meta_query'] ) ? $query->query_vars['meta_query'] : false );
if ( ! empty( $old_meta_query ) ) {
$meta_query = $old_meta_query;
array_push( $meta_query, array( 'relation' => 'OR' ) );
array_push( $meta_query, $new_meta_query );
} else {
$meta_query = array( $new_meta_query );
}
$new_query->set( 'meta_query', $meta_query );
// Set `post_status` and `posts_per_page`
$new_query->set( 'post_status', 'any' );
$new_query->set( 'posts_per_page', -1 );
// Remove action
remove_action( 'pre_get_posts', array( $obj, 'search_backend' ) );
// Search for products
$new_query->set( 'fields', 'ids' );
$result = get_posts( $new_query->query_vars );
$new_ids = $old_product_in;
if ( $result ) {
$new_ids = array_merge( $new_ids, $result );
}
// Search for variation
$new_query->set( 'post_type', 'product_variation' );
$new_query->set( 'fields', 'id=>parent' );
$result = get_posts( $new_query->query_vars );
if ( $result ) {
$new_ids = array_merge( $new_ids, $result );
}
// Set `post__in`
$query->set( 'post__in', array_values( array_unique( $new_ids ) ) );
}
}
/**
* json_search_found_products.
*
* @version 1.0.2
* @since 1.0.2
*
* @todo (dev) customizable `meta_compare` (can be e.g., `=`)
* @todo (dev) append product_id to the title
*/
function json_search_found_products( $products ) {
if ( isset( $_REQUEST['term'] ) && '' !== $_REQUEST['term'] ) {
// Key
$key = alg_wc_ean()->core->ean_key;
// Get products
$found_products = wc_get_products( array(
'type' => array_merge( array_keys( wc_get_product_types() ), array( 'variation' ) ),
'limit' => -1,
'meta_key' => $key,
'meta_value' => wc_clean( $_REQUEST['term'] ),
'meta_compare' => 'LIKE',
'return' => 'ids',
) );
// Products loop
foreach ( $found_products as $product_id ) {
$ean = sprintf( __( 'EAN: %s', 'ean-for-woocommerce' ), get_post_meta( $product_id, $key, true ) );
$products[ $product_id ] = get_the_title( $product_id ) . ' (' . $ean . ')';
}
}
return $products;
}
/**
* search.
*
* @version 4.7.6
* @since 1.0.0
*/
function search( $wp_query ) {
self::_search_frontend( $wp_query, alg_wc_ean()->core->ean_key );
}
/**
* _search_frontend.
*
* @version 4.7.6
* @since 4.7.6
*
* @todo (dev) rewrite?
*/
static function _search_frontend( $wp_query, $key ) {
// Pre-check
if (
! isset( $wp_query->query['s'] ) ||
! isset( $wp_query->query['post_type'] ) || ! in_array( 'product', (array) $wp_query->query['post_type'] ) ||
! apply_filters( 'alg_wc_ean_search', true, $wp_query, $key )
) {
return;
}
// Get `$posts`
global $wpdb;
$posts = $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='{$key}' AND meta_value LIKE %s;",
esc_sql( '%' . $wp_query->query['s'] . '%' ) ) );
if ( ! $posts ) {
return;
}
// Unset `s`
unset( $wp_query->query['s'] );
unset( $wp_query->query_vars['s'] );
// Set `post__in`
$wp_query->query['post__in'] = array();
foreach ( $posts as $id ) {
if ( ( $post = get_post( $id ) ) ) {
if ( 'product_variation' == $post->post_type ) {
$wp_query->query['post__in'][] = $post->post_parent;
$wp_query->query_vars['post__in'][] = $post->post_parent;
} else {
$wp_query->query_vars['post__in'][] = $post->ID;
}
}
}
}
}
endif;
if ( ! function_exists( 'alg_wc_ean_flatsome_search_ajax' ) ) {
/**
* alg_wc_ean_flatsome_search_ajax.
*
* @version 2.1.0
* @since 2.1.0
*/
function alg_wc_ean_flatsome_search_ajax( $search_query, $args, $defaults ) {
return alg_wc_ean()->core->search->flatsome_search_ajax( $search_query, $args, $defaults );
}
}
return new Alg_WC_EAN_Search();

View File

@@ -0,0 +1,100 @@
<?php
/**
* EAN for WooCommerce - Settings Import/Export Class
*
* @version 3.9.0
* @since 3.9.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Import_Export' ) ) :
class Alg_WC_EAN_Settings_Import_Export {
/**
* Constructor.
*
* @version 3.9.0
* @since 3.9.0
*/
function __construct() {
add_action( 'alg_wc_ean_settings_saved', array( $this, 'import_settings' ) );
add_action( 'alg_wc_ean_settings_saved', array( $this, 'export_settings' ) );
}
/**
* import_settings.
*
* @version 3.8.0
* @since 3.1.0
*
* @todo [now] [!!] (feature) separate "Reset all settings" tool?
* @todo [maybe] (dev) better data validation?
*/
function import_settings() {
if ( ! empty( $_FILES['alg_wc_ean_import_settings']['tmp_name'] ) ) {
$content = file_get_contents( $_FILES['alg_wc_ean_import_settings']['tmp_name'] );
$content = json_decode( $content, true );
if ( JSON_ERROR_NONE === json_last_error() ) {
// Reset
global $wpdb;
$deleted = $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'alg_wc_ean%'" );
// Import
$counter = 0;
foreach ( $content as $row ) {
if ( 'alg_wc_ean_version' !== $row['option_name'] ) {
if ( update_option( $row['option_name'], $row['option_value'] ) ) {
$counter++;
}
}
}
if ( is_callable( array( 'WC_Admin_Settings', 'add_message' ) ) ) {
WC_Admin_Settings::add_message( sprintf( __( 'Settings imported (%d option(s) deleted, %d option(s) updated).', 'ean-for-woocommerce' ), $deleted, $counter ) );
}
} elseif ( is_callable( array( 'WC_Admin_Settings', 'add_message' ) ) ) {
WC_Admin_Settings::add_message( sprintf( __( 'Import file error: %s', 'ean-for-woocommerce' ), json_last_error_msg() ) );
}
}
}
/**
* export_settings.
*
* @version 3.8.0
* @since 3.1.0
*
* @todo [now] [!] (dev) remove `length`?
* @todo [now] [!] (dev) recheck headers?
* @todo [now] (dev) redirect page?
*/
function export_settings() {
if ( 'yes' === get_option( 'alg_wc_ean_export_settings', 'no' ) ) {
update_option( 'alg_wc_ean_export_settings', 'no' );
global $wpdb;
$content = $wpdb->get_results( "SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE 'alg_wc_ean%'" );
foreach ( $content as &$row ) {
$row->option_value = maybe_unserialize( $row->option_value );
}
$content = json_encode( $content );
$length = strlen( $content );
header( 'Content-Description: File Transfer' );
header( 'Content-Type: text/plain' );
header( 'Content-Disposition: attachment; filename=alg-wc-ean-settings.txt' );
header( 'Content-Transfer-Encoding: binary' );
header( 'Content-Length: ' . $length );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Expires: 0' );
header( 'Pragma: public' );
echo $content;
exit;
}
}
}
endif;
return new Alg_WC_EAN_Settings_Import_Export();

View File

@@ -0,0 +1,680 @@
<?php
/**
* EAN for WooCommerce - Shortcodes Class
*
* @version 4.6.0
* @since 3.5.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Shortcodes' ) ) :
class Alg_WC_EAN_Shortcodes {
/**
* Constructor.
*
* @version 4.6.0
* @since 3.5.0
*
* @todo (feature) add `[alg_wc_ean_type]` shortcode?
*/
function __construct() {
$this->data = array();
// Shortcodes
add_shortcode( 'alg_wc_ean', array( $this, 'ean_shortcode' ) );
add_shortcode( 'alg_wc_ean_is_unique', array( $this, 'ean_is_unique_shortcode' ) );
add_shortcode( 'alg_wc_ean_is_valid', array( $this, 'ean_is_valid_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_attr', array( $this, 'product_attr_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_image', array( $this, 'product_image_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_name', array( $this, 'product_name_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_sku', array( $this, 'product_sku_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_price', array( $this, 'product_price_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_id', array( $this, 'product_id_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_author_id', array( $this, 'product_author_id_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_meta', array( $this, 'product_meta_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_function', array( $this, 'product_function_shortcode' ) );
add_shortcode( 'alg_wc_ean_product_terms', array( $this, 'product_terms_shortcode' ) );
add_shortcode( 'alg_wc_ean_if', array( $this, 'if_shortcode' ) );
add_shortcode( 'alg_wc_ean_if_product_cat', array( $this, 'if_product_cat_shortcode' ) );
add_shortcode( 'alg_wc_ean_if_product_tag', array( $this, 'if_product_tag_shortcode' ) );
}
/**
* do_shortcode.
*
* @version 3.5.0
* @since 3.1.2
*
* @todo (dev) add `set_data()`, `reset_data()` functions?
*/
function do_shortcode( $content, $data = array() ) {
if ( ! empty( $data ) ) {
$this->data = $data;
}
$result = do_shortcode( $content );
if ( ! empty( $data ) ) {
$this->data = array();
}
return $result;
}
/**
* output.
*
* @version 4.1.0
* @since 3.5.0
*
* @todo (dev) escape: `wp_kses_post()`?
* @todo (dev) `max_length`: add everywhere
*/
function output( $result, $atts ) {
return ( '' === $result ?
$atts['on_empty'] :
(
$atts['before'] .
( ! empty( $atts['max_length'] ) ? substr( $result, 0, $atts['max_length'] ) : $result ) .
$atts['after']
)
);
}
/**
* get_shortcode_att.
*
* @version 3.5.0
* @since 3.5.0
*/
function get_shortcode_att( $att, $atts, $default = '' ) {
return ( ! empty( $atts[ $att ] ) ? $atts[ $att ] : ( ! empty( $this->data[ $att ] ) ? $this->data[ $att ] : $default ) );
}
/**
* get_products.
*
* @version 3.6.0
* @since 3.6.0
*/
function get_products( $atts, $default = false ) {
$product_id = $this->get_shortcode_att( 'product_id', $atts, $default );
$product_ids = array( $product_id );
if ( filter_var( $atts['children'], FILTER_VALIDATE_BOOLEAN ) && ( $product = wc_get_product( $product_id ) ) ) {
$product_ids = array_merge( $product_ids, $product->get_children() );
}
return $product_ids;
}
/**
* if_product_term.
*
* @version 4.6.0
* @since 4.6.0
*
* @todo (dev) `shortcode_atts`
* @todo (dev) rewrite: use `has_term()` instead?
*/
function if_product_term( $taxonomy, $atts, $content = '' ) {
$value = ( isset( $atts['in'] ) && '' !== $atts['in'] ? $atts['in'] : ( isset( $atts['not_in'] ) && '' !== $atts['not_in'] ? $atts['not_in'] : '' ) );
if ( '' !== $value ) {
$atts = array_replace( $atts, array(
'value1' => '{alg_wc_ean_product_terms taxonomy="' . $taxonomy . '" return="slug"}',
'value2' => $value,
'operator' => ( isset( $atts['in'] ) && '' !== $atts['in'] ? 'intersect' : 'not_intersect' ),
) );
unset( $atts['in'] );
unset( $atts['not_in'] );
return $this->if_shortcode( $atts, $content );
}
return '';
}
/**
* if_product_cat_shortcode.
*
* @version 4.6.0
* @since 4.6.0
*/
function if_product_cat_shortcode( $atts, $content = '' ) {
return $this->if_product_term( 'product_cat', $atts, $content );
}
/**
* if_product_tag_shortcode.
*
* @version 4.6.0
* @since 4.6.0
*/
function if_product_tag_shortcode( $atts, $content = '' ) {
return $this->if_product_term( 'product_tag', $atts, $content );
}
/**
* product_terms_shortcode.
*
* @version 4.6.0
* @since 4.6.0
*/
function product_terms_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'yes',
'taxonomy' => 'product_cat',
'return' => 'name',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_terms' );
// Result
$result = '';
if ( ( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) ) ) {
if ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ) {
$product_id = $product_parent_id;
}
$result = implode( ', ', wp_list_pluck( wc_get_product_terms( $product_id, $atts['taxonomy'] ), $atts['return'] ) );
}
return $this->output( $result, $atts );
}
/**
* if_shortcode.
*
* @version 4.6.0
* @since 4.6.0
*
* @todo (dev) `shortcode_atts`
*/
function if_shortcode( $atts, $content = '' ) {
if ( ! isset( $atts['value1'], $atts['operator'], $atts['value2'] ) || ( '' === $content && ! isset( $atts['then'] ) ) ) {
return '';
}
$value1 = do_shortcode( str_replace( array( '{', '}' ), array( '[', ']' ), $atts['value1'] ) );
$value2 = do_shortcode( str_replace( array( '{', '}' ), array( '[', ']' ), $atts['value2'] ) );
$then = ( '' === $content ? str_replace( array( '{', '}' ), array( '[', ']' ), $atts['then'] ) : $content );
$else = ( isset( $atts['else'] ) ? str_replace( array( '{', '}' ), array( '[', ']' ), $atts['else'] ) : '' );
return do_shortcode( ( $this->if_shortcode_operator( $value1, $atts['operator'], $value2 ) ? $then : $else ) );
}
/**
* if_shortcode_operator.
*
* @version 4.6.0
* @since 4.6.0
*/
function if_shortcode_operator( $value1, $operator, $value2 ) {
switch ( $operator ) {
case 'equal':
return ( $value1 == $value2 );
case 'not_equal':
return ( $value1 != $value2 );
case 'less':
return ( $value1 < $value2 );
case 'less_or_equal':
return ( $value1 <= $value2 );
case 'greater':
return ( $value1 > $value2 );
case 'greater_or_equal':
return ( $value1 >= $value2 );
case 'in':
return ( in_array( $value1, array_map( 'trim', explode( ',', $value2 ) ) ) );
case 'not_in':
return ( ! in_array( $value1, array_map( 'trim', explode( ',', $value2 ) ) ) );
case 'intersect':
return ( ! empty( array_intersect( array_map( 'trim', explode( ',', $value1 ) ), array_map( 'trim', explode( ',', $value2 ) ) ) ) );
case 'not_intersect':
return ( empty( array_intersect( array_map( 'trim', explode( ',', $value1 ) ), array_map( 'trim', explode( ',', $value2 ) ) ) ) );
}
return false;
}
/**
* product_function_shortcode.
*
* @version 3.6.0
* @since 3.6.0
*/
function product_function_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'no',
'name' => '',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_function' );
// Check the required atts
if ( '' === $atts['name'] || ! ( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) ) ) {
return '';
}
// Product ID
if ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ) {
$product_id = $product_parent_id;
}
// Check if function exists
if ( ! ( $product = wc_get_product( $product_id ) ) || ! is_callable( array( $product, $atts['name'] ) ) ) {
return '';
}
// Result
$result = $product->{$atts['name']}();
return $this->output( $result, $atts );
}
/**
* product_meta_shortcode.
*
* @version 3.6.0
* @since 3.6.0
*/
function product_meta_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'no',
'key' => '',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_meta' );
// Check the required atts
if ( '' === $atts['key'] || ! ( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) ) ) {
return '';
}
// Product ID
if ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ) {
$product_id = $product_parent_id;
}
// Result
$result = get_post_meta( $product_id, $atts['key'], true );
return $this->output( $result, $atts );
}
/**
* product_image_shortcode.
*
* @version 4.4.3
* @since 3.5.0
*/
function product_image_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'no',
'output' => 'img',
'size' => 'woocommerce_thumbnail',
'width' => 30, // px // for `output = img`
'height' => 30, // px // for `output = img`
'is_in_pdf' => false, // for `output = img`
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_image' );
// Result
$result = '';
if (
( 'url' === $atts['output'] || ! $this->get_shortcode_att( 'is_in_pdf', $atts, false ) || function_exists( 'curl_init' ) ) &&
( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) )
) {
if ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ) {
$product_id = $product_parent_id;
}
if ( $product = wc_get_product( $product_id ) ) {
if ( ( $img_id = $product->get_image_id() ) && ( $img_url = wp_get_attachment_image_src( $img_id, $atts['size'] ) ) ) {
$img_url = $img_url[0];
}
if ( ! $img_url ) {
$img_url = wc_placeholder_img_src( $atts['size'] );
}
$img_url = esc_url( $img_url );
$result = ( 'url' === $atts['output'] ? $img_url : '<img src="' . $img_url . '" width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '">' );
}
}
return $this->output( $result, $atts );
}
/**
* product_name_shortcode.
*
* @version 3.5.0
* @since 3.5.0
*/
function product_name_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'no',
'type' => 'name',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_name' );
// Result
$result = '';
if ( ( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) ) ) {
if ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ) {
$product_id = $product_parent_id;
}
if ( 'name' === $atts['type'] ) {
if ( ( $product = wc_get_product( $product_id ) ) ) {
$result = $product->get_formatted_name();
}
} else { // 'title'
$result = get_the_title( $product_id );
}
}
return $this->output( $result, $atts );
}
/**
* product_sku_shortcode.
*
* @version 4.1.0
* @since 3.5.0
*/
function product_sku_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'max_length' => false,
'parent' => 'no',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_sku' );
// Result
$result = '';
if ( ( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) ) ) {
if ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ) {
$product_id = $product_parent_id;
}
if ( ( $product = wc_get_product( $product_id ) ) ) {
$result = $product->get_sku();
}
}
return $this->output( $result, $atts );
}
/**
* product_price_shortcode.
*
* @version 3.5.0
* @since 3.5.0
*
* @todo (dev) `sale`: do we really need to use `get_regular_price()` as a fallback?
* @todo (desc) `sale` and `regular` prices won't work for a) variable products, b) parent of a variation
*/
function product_price_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'no',
'raw' => 'no',
'type' => 'final',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_price' );
// Result
$result = '';
if ( ( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) ) ) {
if ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ) {
$product_id = $product_parent_id;
}
if ( ( $product = wc_get_product( $product_id ) ) ) {
switch ( $atts['type'] ) {
case 'final':
$result = ( 'yes' === $atts['raw'] ? $product->get_price() : $product->get_price_html() );
break;
case 'regular':
$result = ( 'yes' === $atts['raw'] ? $product->get_regular_price() : wc_price( $product->get_regular_price() ) );
break;
case 'sale':
$price = ( '' === ( $sale = $product->get_sale_price() ) ? $product->get_regular_price() : $sale );
$result = ( 'yes' === $atts['raw'] ? $price : wc_price( $price ) );
break;
}
}
}
return $this->output( $result, $atts );
}
/**
* product_id_shortcode.
*
* @version 3.5.0
* @since 3.5.0
*/
function product_id_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'no',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_id' );
// Result
$product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() );
$result = ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ? $product_parent_id : $product_id );
return $this->output( $result, $atts );
}
/**
* product_author_id_shortcode.
*
* @version 4.0.0
* @since 4.0.0
*/
function product_author_id_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'min_length' => 0,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'no',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_author_id' );
// Product ID
if ( ! ( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) ) ) {
return '';
}
$product_id = ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ? $product_parent_id : $product_id );
// Author ID
$result = get_post_field( 'post_author', $product_id );
if ( ! empty( $atts['min_length'] ) ) {
$result = str_pad( $result, $atts['min_length'], '0', STR_PAD_LEFT );
}
return $this->output( $result, $atts );
}
/**
* product_attr_shortcode.
*
* @version 3.5.0
* @since 2.7.0
*
* @todo (feature) multiple attributes (comma-separated)
* @todo (feature) all attributes at once (maybe use `WC_Product::get_attributes()`?
* @todo (feature) all attributes starting with X
*/
function product_attr_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'parent' => 'no',
'attr' => '',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_product_attr' );
// Result
$result = '';
if ( '' !== $atts['attr'] && ( $product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() ) ) ) {
if ( 'yes' === $atts['parent'] && 0 != ( $product_parent_id = wp_get_post_parent_id ( $product_id ) ) ) {
$product_id = $product_parent_id;
}
if ( ( $product = wc_get_product( $product_id ) ) && is_callable( array( $product, 'get_attribute' ) ) ) {
$result = $product->get_attribute( $atts['attr'] );
}
}
return $this->output( $result, $atts );
}
/**
* ean_is_unique_shortcode.
*
* @version 4.4.6
* @since 4.4.6
*/
function ean_is_unique_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'ean' => '',
'unique_text' => '<span style="color:green;">' . esc_html__( 'Unique EAN', 'ean-for-woocommerce' ) . '</span>',
'duplicate_text' => '<span style="color:red;">' . esc_html__( 'Duplicated EAN', 'ean-for-woocommerce' ) . '</span>',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_is_unique' );
$ean = $this->get_shortcode_att( 'ean', $atts, '' );
$product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() );
// Result
$result = '';
if ( ! empty( $ean ) ) {
$result = ( ! alg_wc_ean()->core->do_ean_exist( $ean, $product_id ) ? $atts['unique_text'] : $atts['duplicate_text'] );
}
return $this->output( $result, $atts );
}
/**
* ean_is_valid_shortcode.
*
* @version 4.4.6
* @since 4.4.6
*/
function ean_is_valid_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'ean' => '',
'valid_text' => '<span style="color:green;">' . esc_html__( 'Valid EAN', 'ean-for-woocommerce' ) . '</span>',
'invalid_text' => '<span style="color:red;">' . esc_html__( 'Invalid EAN', 'ean-for-woocommerce' ) . '</span>',
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean_is_valid' );
$ean = $this->get_shortcode_att( 'ean', $atts, '' );
$product_id = $this->get_shortcode_att( 'product_id', $atts, get_the_ID() );
// Result
$result = '';
if ( ! empty( $ean ) ) {
$result = ( alg_wc_ean()->core->is_valid_ean( $ean, $product_id ) ? $atts['valid_text'] : $atts['invalid_text'] );
}
return $this->output( $result, $atts );
}
/**
* ean_shortcode.
*
* @version 3.6.0
* @since 1.5.1
*
* @todo (dev) `$atts['ean']`: ` if ( false !== ( $ean = ( '' !== $atts['ean'] ? $atts['ean'] : ( ! empty( $this->data['ean'] ) ? $this->data['ean'] : false ) ) ) ) { return $this->output( $ean, $atts ); }`
* @todo (feature) `parent`? (same for barcodes)
* @todo (dev) check if valid?
* @todo (feature) add `children` attribute to all shortcodes, e.g., `product_attr_shortcode()`
*/
function ean_shortcode( $atts, $content = '' ) {
// Atts
$default_atts = array(
'product_id' => false,
'before' => '',
'after' => '',
'on_empty' => '',
'children' => 'no',
'glue' => ', ', // for `children = yes`
);
$atts = shortcode_atts( $default_atts, $atts, 'alg_wc_ean' );
// Products
$product_ids = $this->get_products( $atts );
// Result
$result = array();
foreach ( $product_ids as $product_id ) {
$result[] = alg_wc_ean()->core->get_ean( $product_id );
}
$result = implode( $atts['glue'], $result );
return $this->output( $result, $atts );
}
}
endif;
return new Alg_WC_EAN_Shortcodes();

View File

@@ -0,0 +1,221 @@
<?php
/**
* EAN for WooCommerce - Main Class
*
* @version 4.7.3
* @since 1.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN' ) ) :
final class Alg_WC_EAN {
/**
* Plugin version.
*
* @var string
* @since 1.0.0
*/
public $version = ALG_WC_EAN_VERSION;
/**
* @var Alg_WC_EAN The single instance of the class
* @since 1.0.0
*/
protected static $_instance = null;
/**
* Main Alg_WC_EAN Instance
*
* Ensures only one instance of Alg_WC_EAN is loaded or can be loaded.
*
* @version 1.0.0
* @since 1.0.0
*
* @static
* @return Alg_WC_EAN - Main instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Alg_WC_EAN Constructor.
*
* @version 4.5.0
* @since 1.0.0
*
* @access public
*/
function __construct() {
// Check for active WooCommerce plugin
if ( ! function_exists( 'WC' ) ) {
return;
}
// Set up localisation
add_action( 'init', array( $this, 'localize' ) );
// Declare compatibility with custom order tables for WooCommerce
add_action( 'before_woocommerce_init', array( $this, 'wc_declare_compatibility' ) );
// Pro
if ( 'ean-for-woocommerce-pro.php' === basename( ALG_WC_EAN_FILE ) ) {
$this->pro = require_once( 'pro/class-alg-wc-ean-pro.php' );
}
// Include required files
$this->includes();
// Admin
if ( is_admin() ) {
$this->admin();
}
}
/**
* localize.
*
* @version 2.2.0
* @since 2.0.0
*/
function localize() {
load_plugin_textdomain( 'ean-for-woocommerce', false, dirname( plugin_basename( ALG_WC_EAN_FILE ) ) . '/langs/' );
}
/**
* wc_declare_compatibility.
*
* @version 4.7.3
* @since 4.5.0
*
* @see https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book#declaring-extension-incompatibility
*/
function wc_declare_compatibility() {
if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
$files = ( defined( 'ALG_WC_EAN_FILE_FREE' ) ? array( ALG_WC_EAN_FILE, ALG_WC_EAN_FILE_FREE ) : array( ALG_WC_EAN_FILE ) );
foreach ( $files as $file ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', $file, true );
}
}
}
/**
* includes.
*
* @version 2.2.0
* @since 1.0.0
*/
function includes() {
$this->core = require_once( 'class-alg-wc-ean-core.php' );
}
/**
* admin.
*
* @version 2.2.0
* @since 1.0.0
*/
function admin() {
// Action links
add_filter( 'plugin_action_links_' . plugin_basename( ALG_WC_EAN_FILE ), array( $this, 'action_links' ) );
// Settings
add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_woocommerce_settings_tab' ) );
// Version update
if ( get_option( 'alg_wc_ean_version', '' ) !== $this->version ) {
add_action( 'admin_init', array( $this, 'version_updated' ) );
}
}
/**
* action_links.
*
* @version 2.2.0
* @since 1.0.0
*
* @param mixed $links
* @return array
*/
function action_links( $links ) {
$custom_links = array();
$custom_links[] = '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=alg_wc_ean' ) . '">' . __( 'Settings', 'woocommerce' ) . '</a>';
if ( 'ean-for-woocommerce.php' === basename( ALG_WC_EAN_FILE ) ) {
$custom_links[] = '<a target="_blank" style="font-weight: bold; color: green;" href="https://wpfactory.com/item/ean-for-woocommerce/">' .
__( 'Go Pro', 'ean-for-woocommerce' ) . '</a>';
}
return array_merge( $custom_links, $links );
}
/**
* add_woocommerce_settings_tab.
*
* @version 2.2.0
* @since 1.0.0
*/
function add_woocommerce_settings_tab( $settings ) {
$settings[] = require_once( 'settings/class-alg-wc-ean-settings.php' );
return $settings;
}
/**
* version_updated.
*
* @version 2.9.0
* @since 1.0.0
*/
function version_updated() {
update_option( 'alg_wc_ean_version', $this->version );
/**
* Handle deprecated options.
*
* @deprecated 2.9.0
*/
if ( false !== ( $deprecated_options = get_option( 'alg_wc_ean_tool_product_generate_on', false ) ) ) {
if ( isset( $deprecated_options['insert_product'] ) && 'yes' === $deprecated_options['insert_product'] ) {
update_option( 'alg_wc_ean_tool_product_action_on_new', 'generate' );
}
if ( isset( $deprecated_options['update_product'] ) && 'yes' === $deprecated_options['update_product'] ) {
update_option( 'alg_wc_ean_tool_product_action_on_update', 'generate' );
}
delete_option( 'alg_wc_ean_tool_product_generate_on' );
}
}
/**
* plugin_url.
*
* @version 2.2.0
* @since 1.0.0
*
* @return string
*/
function plugin_url() {
return untrailingslashit( plugin_dir_url( ALG_WC_EAN_FILE ) );
}
/**
* plugin_path.
*
* @version 2.2.0
* @since 1.0.0
*
* @return string
*/
function plugin_path() {
return untrailingslashit( plugin_dir_path( ALG_WC_EAN_FILE ) );
}
}
endif;

View File

@@ -0,0 +1,80 @@
/**
* EAN for WooCommerce - Variations
*
* @version 4.4.0
* @since 1.0.0
*
* @author Algoritmika Ltd
*/
jQuery( document ).ready( function() {
var variations_form = jQuery( alg_wc_ean_variations_obj.variations_form );
if ( jQuery( 'body' ).hasClass( 'single-product' ) && variations_form.length > 0 ) { // is single variable product page
var ean = variations_form.closest( alg_wc_ean_variations_obj.variations_form_closest ).find( '.ean' );
if ( ean.length > 0 ) { // do ean
var ean_reset = ean.text();
var ean_parent = ean.parent();
alg_wc_ean_maybe_hide();
alg_wc_ean_variations();
}
}
/**
* alg_wc_ean_variations
*
* @version 1.3.0
* @since 1.0.0
*/
function alg_wc_ean_variations() {
variations_form.on( 'found_variation', function( event, variation ) {
if ( variation.ean ) {
alg_wc_ean_show( variation );
} else {
alg_wc_ean_reset();
}
} );
variations_form.on( 'reset_data', alg_wc_ean_reset );
}
/**
* alg_wc_ean_show
*
* @version 1.3.0
* @since 1.0.0
*/
function alg_wc_ean_show( variation ) {
if ( variation.ean ) {
ean.text( variation.ean );
ean_parent.show();
}
}
/**
* alg_wc_ean_reset
*
* @version 1.3.0
* @since 1.0.0
*/
function alg_wc_ean_reset() {
if ( ean_reset !== ean.text() ) {
ean.text( ean_reset );
}
alg_wc_ean_maybe_hide();
}
/**
* alg_wc_ean_maybe_hide
*
* @version 1.3.0
* @since 1.0.0
*
* @todo [later] `do_hide`
*/
function alg_wc_ean_maybe_hide() {
if ( '' == ean_reset ) {
ean_parent.hide();
}
}
} );

View File

@@ -0,0 +1 @@
jQuery(document).ready(function(){var variations_form=jQuery(alg_wc_ean_variations_obj.variations_form);if(jQuery('body').hasClass('single-product')&&variations_form.length>0){var ean=variations_form.closest(alg_wc_ean_variations_obj.variations_form_closest).find('.ean');if(ean.length>0){var ean_reset=ean.text();var ean_parent=ean.parent();alg_wc_ean_maybe_hide();alg_wc_ean_variations()}}function alg_wc_ean_variations(){variations_form.on('found_variation',function(event,variation){if(variation.ean){alg_wc_ean_show(variation)}else{alg_wc_ean_reset()}});variations_form.on('reset_data',alg_wc_ean_reset)}function alg_wc_ean_show(variation){if(variation.ean){ean.text(variation.ean);ean_parent.show()}}function alg_wc_ean_reset(){if(ean_reset!==ean.text()){ean.text(ean_reset)}alg_wc_ean_maybe_hide()}function alg_wc_ean_maybe_hide(){if(''==ean_reset){ean_parent.hide()}}});

View File

@@ -0,0 +1,364 @@
<?php
/**
* EAN for WooCommerce - PDF Page Formats
*
* @version 3.0.0
* @since 2.0.0
*
* @author Algoritmika Ltd
*
* @see https://github.com/tecnickcom/TCPDF/blob/6.3.5/include/tcpdf_static.php#L2129
*/
defined( 'ABSPATH' ) || exit;
return array(
// ISO 216 A Series + 2 SIS 014711 extensions
'A0' => array( 2383.937, 3370.394 ), // = ( 841 x 1189 ) mm = ( 33.11 x 46.81 ) in
'A1' => array( 1683.780, 2383.937 ), // = ( 594 x 841 ) mm = ( 23.39 x 33.11 ) in
'A2' => array( 1190.551, 1683.780 ), // = ( 420 x 594 ) mm = ( 16.54 x 23.39 ) in
'A3' => array( 841.890, 1190.551 ), // = ( 297 x 420 ) mm = ( 11.69 x 16.54 ) in
'A4' => array( 595.276, 841.890 ), // = ( 210 x 297 ) mm = ( 8.27 x 11.69 ) in
'A5' => array( 419.528, 595.276 ), // = ( 148 x 210 ) mm = ( 5.83 x 8.27 ) in
'A6' => array( 297.638, 419.528 ), // = ( 105 x 148 ) mm = ( 4.13 x 5.83 ) in
'A7' => array( 209.764, 297.638 ), // = ( 74 x 105 ) mm = ( 2.91 x 4.13 ) in
'A8' => array( 147.402, 209.764 ), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in
'A9' => array( 104.882, 147.402 ), // = ( 37 x 52 ) mm = ( 1.46 x 2.05 ) in
'A10' => array( 73.701, 104.882 ), // = ( 26 x 37 ) mm = ( 1.02 x 1.46 ) in
'A11' => array( 51.024, 73.701 ), // = ( 18 x 26 ) mm = ( 0.71 x 1.02 ) in
'A12' => array( 36.850, 51.024 ), // = ( 13 x 18 ) mm = ( 0.51 x 0.71 ) in
// ISO 216 B Series + 2 SIS 014711 extensions
'B0' => array( 2834.646, 4008.189 ), // = ( 1000 x 1414 ) mm = ( 39.37 x 55.67 ) in
'B1' => array( 2004.094, 2834.646 ), // = ( 707 x 1000 ) mm = ( 27.83 x 39.37 ) in
'B2' => array( 1417.323, 2004.094 ), // = ( 500 x 707 ) mm = ( 19.69 x 27.83 ) in
'B3' => array( 1000.630, 1417.323 ), // = ( 353 x 500 ) mm = ( 13.90 x 19.69 ) in
'B4' => array( 708.661, 1000.630 ), // = ( 250 x 353 ) mm = ( 9.84 x 13.90 ) in
'B5' => array( 498.898, 708.661 ), // = ( 176 x 250 ) mm = ( 6.93 x 9.84 ) in
'B6' => array( 354.331, 498.898 ), // = ( 125 x 176 ) mm = ( 4.92 x 6.93 ) in
'B7' => array( 249.449, 354.331 ), // = ( 88 x 125 ) mm = ( 3.46 x 4.92 ) in
'B8' => array( 175.748, 249.449 ), // = ( 62 x 88 ) mm = ( 2.44 x 3.46 ) in
'B9' => array( 124.724, 175.748 ), // = ( 44 x 62 ) mm = ( 1.73 x 2.44 ) in
'B10' => array( 87.874, 124.724 ), // = ( 31 x 44 ) mm = ( 1.22 x 1.73 ) in
'B11' => array( 62.362, 87.874 ), // = ( 22 x 31 ) mm = ( 0.87 x 1.22 ) in
'B12' => array( 42.520, 62.362 ), // = ( 15 x 22 ) mm = ( 0.59 x 0.87 ) in
// ISO 216 C Series + 2 SIS 014711 extensions + 5 EXTENSION
'C0' => array( 2599.370, 3676.535 ), // = ( 917 x 1297 ) mm = ( 36.10 x 51.06 ) in
'C1' => array( 1836.850, 2599.370 ), // = ( 648 x 917 ) mm = ( 25.51 x 36.10 ) in
'C2' => array( 1298.268, 1836.850 ), // = ( 458 x 648 ) mm = ( 18.03 x 25.51 ) in
'C3' => array( 918.425, 1298.268 ), // = ( 324 x 458 ) mm = ( 12.76 x 18.03 ) in
'C4' => array( 649.134, 918.425 ), // = ( 229 x 324 ) mm = ( 9.02 x 12.76 ) in
'C5' => array( 459.213, 649.134 ), // = ( 162 x 229 ) mm = ( 6.38 x 9.02 ) in
'C6' => array( 323.150, 459.213 ), // = ( 114 x 162 ) mm = ( 4.49 x 6.38 ) in
'C7' => array( 229.606, 323.150 ), // = ( 81 x 114 ) mm = ( 3.19 x 4.49 ) in
'C8' => array( 161.575, 229.606 ), // = ( 57 x 81 ) mm = ( 2.24 x 3.19 ) in
'C9' => array( 113.386, 161.575 ), // = ( 40 x 57 ) mm = ( 1.57 x 2.24 ) in
'C10' => array( 79.370, 113.386 ), // = ( 28 x 40 ) mm = ( 1.10 x 1.57 ) in
'C11' => array( 56.693, 79.370 ), // = ( 20 x 28 ) mm = ( 0.79 x 1.10 ) in
'C12' => array( 39.685, 56.693 ), // = ( 14 x 20 ) mm = ( 0.55 x 0.79 ) in
'C76' => array( 229.606, 459.213 ), // = ( 81 x 162 ) mm = ( 3.19 x 6.38 ) in
'DL' => array( 311.811, 623.622 ), // = ( 110 x 220 ) mm = ( 4.33 x 8.66 ) in
'DLE' => array( 323.150, 637.795 ), // = ( 114 x 225 ) mm = ( 4.49 x 8.86 ) in
'DLX' => array( 340.158, 666.142 ), // = ( 120 x 235 ) mm = ( 4.72 x 9.25 ) in
'DLP' => array( 280.630, 595.276 ), // = ( 99 x 210 ) mm = ( 3.90 x 8.27 ) in (1/3 A4)
// SIS 014711 E Series
'E0' => array( 2491.654, 3517.795 ), // = ( 879 x 1241 ) mm = ( 34.61 x 48.86 ) in
'E1' => array( 1757.480, 2491.654 ), // = ( 620 x 879 ) mm = ( 24.41 x 34.61 ) in
'E2' => array( 1247.244, 1757.480 ), // = ( 440 x 620 ) mm = ( 17.32 x 24.41 ) in
'E3' => array( 878.740, 1247.244 ), // = ( 310 x 440 ) mm = ( 12.20 x 17.32 ) in
'E4' => array( 623.622, 878.740 ), // = ( 220 x 310 ) mm = ( 8.66 x 12.20 ) in
'E5' => array( 439.370, 623.622 ), // = ( 155 x 220 ) mm = ( 6.10 x 8.66 ) in
'E6' => array( 311.811, 439.370 ), // = ( 110 x 155 ) mm = ( 4.33 x 6.10 ) in
'E7' => array( 221.102, 311.811 ), // = ( 78 x 110 ) mm = ( 3.07 x 4.33 ) in
'E8' => array( 155.906, 221.102 ), // = ( 55 x 78 ) mm = ( 2.17 x 3.07 ) in
'E9' => array( 110.551, 155.906 ), // = ( 39 x 55 ) mm = ( 1.54 x 2.17 ) in
'E10' => array( 76.535, 110.551 ), // = ( 27 x 39 ) mm = ( 1.06 x 1.54 ) in
'E11' => array( 53.858, 76.535 ), // = ( 19 x 27 ) mm = ( 0.75 x 1.06 ) in
'E12' => array( 36.850, 53.858 ), // = ( 13 x 19 ) mm = ( 0.51 x 0.75 ) in
// SIS 014711 G Series
'G0' => array( 2715.591, 3838.110 ), // = ( 958 x 1354 ) mm = ( 37.72 x 53.31 ) in
'G1' => array( 1919.055, 2715.591 ), // = ( 677 x 958 ) mm = ( 26.65 x 37.72 ) in
'G2' => array( 1357.795, 1919.055 ), // = ( 479 x 677 ) mm = ( 18.86 x 26.65 ) in
'G3' => array( 958.110, 1357.795 ), // = ( 338 x 479 ) mm = ( 13.31 x 18.86 ) in
'G4' => array( 677.480, 958.110 ), // = ( 239 x 338 ) mm = ( 9.41 x 13.31 ) in
'G5' => array( 479.055, 677.480 ), // = ( 169 x 239 ) mm = ( 6.65 x 9.41 ) in
'G6' => array( 337.323, 479.055 ), // = ( 119 x 169 ) mm = ( 4.69 x 6.65 ) in
'G7' => array( 238.110, 337.323 ), // = ( 84 x 119 ) mm = ( 3.31 x 4.69 ) in
'G8' => array( 167.244, 238.110 ), // = ( 59 x 84 ) mm = ( 2.32 x 3.31 ) in
'G9' => array( 119.055, 167.244 ), // = ( 42 x 59 ) mm = ( 1.65 x 2.32 ) in
'G10' => array( 82.205, 119.055 ), // = ( 29 x 42 ) mm = ( 1.14 x 1.65 ) in
'G11' => array( 59.528, 82.205 ), // = ( 21 x 29 ) mm = ( 0.83 x 1.14 ) in
'G12' => array( 39.685, 59.528 ), // = ( 14 x 21 ) mm = ( 0.55 x 0.83 ) in
// ISO Press
'RA0' => array( 2437.795, 3458.268 ), // = ( 860 x 1220 ) mm = ( 33.86 x 48.03 ) in
'RA1' => array( 1729.134, 2437.795 ), // = ( 610 x 860 ) mm = ( 24.02 x 33.86 ) in
'RA2' => array( 1218.898, 1729.134 ), // = ( 430 x 610 ) mm = ( 16.93 x 24.02 ) in
'RA3' => array( 864.567, 1218.898 ), // = ( 305 x 430 ) mm = ( 12.01 x 16.93 ) in
'RA4' => array( 609.449, 864.567 ), // = ( 215 x 305 ) mm = ( 8.46 x 12.01 ) in
'SRA0' => array( 2551.181, 3628.346 ), // = ( 900 x 1280 ) mm = ( 35.43 x 50.39 ) in
'SRA1' => array( 1814.173, 2551.181 ), // = ( 640 x 900 ) mm = ( 25.20 x 35.43 ) in
'SRA2' => array( 1275.591, 1814.173 ), // = ( 450 x 640 ) mm = ( 17.72 x 25.20 ) in
'SRA3' => array( 907.087, 1275.591 ), // = ( 320 x 450 ) mm = ( 12.60 x 17.72 ) in
'SRA4' => array( 637.795, 907.087 ), // = ( 225 x 320 ) mm = ( 8.86 x 12.60 ) in
// German DIN 476
'4A0' => array( 4767.874, 6740.787 ), // = ( 1682 x 2378 ) mm = ( 66.22 x 93.62 ) in
'2A0' => array( 3370.394, 4767.874 ), // = ( 1189 x 1682 ) mm = ( 46.81 x 66.22 ) in
// Variations on the ISO Standard
'A2_EXTRA' => array( 1261.417, 1754.646 ), // = ( 445 x 619 ) mm = ( 17.52 x 24.37 ) in
'A3+' => array( 932.598, 1369.134 ), // = ( 329 x 483 ) mm = ( 12.95 x 19.02 ) in
'A3_EXTRA' => array( 912.756, 1261.417 ), // = ( 322 x 445 ) mm = ( 12.68 x 17.52 ) in
'A3_SUPER' => array( 864.567, 1440.000 ), // = ( 305 x 508 ) mm = ( 12.01 x 20.00 ) in
'SUPER_A3' => array( 864.567, 1380.472 ), // = ( 305 x 487 ) mm = ( 12.01 x 19.17 ) in
'A4_EXTRA' => array( 666.142, 912.756 ), // = ( 235 x 322 ) mm = ( 9.25 x 12.68 ) in
'A4_SUPER' => array( 649.134, 912.756 ), // = ( 229 x 322 ) mm = ( 9.02 x 12.68 ) in
'SUPER_A4' => array( 643.465, 1009.134 ), // = ( 227 x 356 ) mm = ( 8.94 x 14.02 ) in
'A4_LONG' => array( 595.276, 986.457 ), // = ( 210 x 348 ) mm = ( 8.27 x 13.70 ) in
'F4' => array( 595.276, 935.433 ), // = ( 210 x 330 ) mm = ( 8.27 x 12.99 ) in
'SO_B5_EXTRA' => array( 572.598, 782.362 ), // = ( 202 x 276 ) mm = ( 7.95 x 10.87 ) in
'A5_EXTRA' => array( 490.394, 666.142 ), // = ( 173 x 235 ) mm = ( 6.81 x 9.25 ) in
// ANSI Series
'ANSI_E' => array( 2448.000, 3168.000 ), // = ( 864 x 1118 ) mm = ( 34.00 x 44.00 ) in
'ANSI_D' => array( 1584.000, 2448.000 ), // = ( 559 x 864 ) mm = ( 22.00 x 34.00 ) in
'ANSI_C' => array( 1224.000, 1584.000 ), // = ( 432 x 559 ) mm = ( 17.00 x 22.00 ) in
'ANSI_B' => array( 792.000, 1224.000 ), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
'ANSI_A' => array( 612.000, 792.000 ), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
// Traditional 'Loose' North American Paper Sizes
'USLEDGER' => array( 1224.000, 792.000 ), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in
'LEDGER' => array( 1224.000, 792.000 ), // = ( 432 x 279 ) mm = ( 17.00 x 11.00 ) in
'ORGANIZERK' => array( 792.000, 1224.000 ), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
'BIBLE' => array( 792.000, 1224.000 ), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
'USTABLOID' => array( 792.000, 1224.000 ), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
'TABLOID' => array( 792.000, 1224.000 ), // = ( 279 x 432 ) mm = ( 11.00 x 17.00 ) in
'ORGANIZERM' => array( 612.000, 792.000 ), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
'USLETTER' => array( 612.000, 792.000 ), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
'LETTER' => array( 612.000, 792.000 ), // = ( 216 x 279 ) mm = ( 8.50 x 11.00 ) in
'USLEGAL' => array( 612.000, 1008.000 ), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in
'LEGAL' => array( 612.000, 1008.000 ), // = ( 216 x 356 ) mm = ( 8.50 x 14.00 ) in
'GOVERNMENTLETTER' => array( 576.000, 756.000 ), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in
'GLETTER' => array( 576.000, 756.000 ), // = ( 203 x 267 ) mm = ( 8.00 x 10.50 ) in
'JUNIORLEGAL' => array( 576.000, 360.000 ), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in
'JLEGAL' => array( 576.000, 360.000 ), // = ( 203 x 127 ) mm = ( 8.00 x 5.00 ) in
// Other North American Paper Sizes
'QUADDEMY' => array( 2520.000, 3240.000 ), // = ( 889 x 1143 ) mm = ( 35.00 x 45.00 ) in
'SUPER_B' => array( 936.000, 1368.000 ), // = ( 330 x 483 ) mm = ( 13.00 x 19.00 ) in
'QUARTO' => array( 648.000, 792.000 ), // = ( 229 x 279 ) mm = ( 9.00 x 11.00 ) in
'GOVERNMENTLEGAL' => array( 612.000, 936.000 ), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in
'FOLIO' => array( 612.000, 936.000 ), // = ( 216 x 330 ) mm = ( 8.50 x 13.00 ) in
'MONARCH' => array( 522.000, 756.000 ), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in
'EXECUTIVE' => array( 522.000, 756.000 ), // = ( 184 x 267 ) mm = ( 7.25 x 10.50 ) in
'ORGANIZERL' => array( 396.000, 612.000 ), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
'STATEMENT' => array( 396.000, 612.000 ), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
'MEMO' => array( 396.000, 612.000 ), // = ( 140 x 216 ) mm = ( 5.50 x 8.50 ) in
'FOOLSCAP' => array( 595.440, 936.000 ), // = ( 210 x 330 ) mm = ( 8.27 x 13.00 ) in
'COMPACT' => array( 306.000, 486.000 ), // = ( 108 x 171 ) mm = ( 4.25 x 6.75 ) in
'ORGANIZERJ' => array( 198.000, 360.000 ), // = ( 70 x 127 ) mm = ( 2.75 x 5.00 ) in
// Canadian standard CAN 2-9.60M
'P1' => array( 1587.402, 2437.795 ), // = ( 560 x 860 ) mm = ( 22.05 x 33.86 ) in
'P2' => array( 1218.898, 1587.402 ), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in
'P3' => array( 793.701, 1218.898 ), // = ( 280 x 430 ) mm = ( 11.02 x 16.93 ) in
'P4' => array( 609.449, 793.701 ), // = ( 215 x 280 ) mm = ( 8.46 x 11.02 ) in
'P5' => array( 396.850, 609.449 ), // = ( 140 x 215 ) mm = ( 5.51 x 8.46 ) in
'P6' => array( 303.307, 396.850 ), // = ( 107 x 140 ) mm = ( 4.21 x 5.51 ) in
// North American Architectural Sizes
'ARCH_E' => array( 2592.000, 3456.000 ), // = ( 914 x 1219 ) mm = ( 36.00 x 48.00 ) in
'ARCH_E1' => array( 2160.000, 3024.000 ), // = ( 762 x 1067 ) mm = ( 30.00 x 42.00 ) in
'ARCH_D' => array( 1728.000, 2592.000 ), // = ( 610 x 914 ) mm = ( 24.00 x 36.00 ) in
'BROADSHEET' => array( 1296.000, 1728.000 ), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in
'ARCH_C' => array( 1296.000, 1728.000 ), // = ( 457 x 610 ) mm = ( 18.00 x 24.00 ) in
'ARCH_B' => array( 864.000, 1296.000 ), // = ( 305 x 457 ) mm = ( 12.00 x 18.00 ) in
'ARCH_A' => array( 648.000, 864.000 ), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in
// -- North American Envelope Sizes
// - Announcement Envelopes
'ANNENV_A2' => array( 314.640, 414.000 ), // = ( 111 x 146 ) mm = ( 4.37 x 5.75 ) in
'ANNENV_A6' => array( 342.000, 468.000 ), // = ( 121 x 165 ) mm = ( 4.75 x 6.50 ) in
'ANNENV_A7' => array( 378.000, 522.000 ), // = ( 133 x 184 ) mm = ( 5.25 x 7.25 ) in
'ANNENV_A8' => array( 396.000, 584.640 ), // = ( 140 x 206 ) mm = ( 5.50 x 8.12 ) in
'ANNENV_A10' => array( 450.000, 692.640 ), // = ( 159 x 244 ) mm = ( 6.25 x 9.62 ) in
'ANNENV_SLIM' => array( 278.640, 638.640 ), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in
// - Commercial Envelopes
'COMMENV_N6_1/4' => array( 252.000, 432.000 ), // = ( 89 x 152 ) mm = ( 3.50 x 6.00 ) in
'COMMENV_N6_3/4' => array( 260.640, 468.000 ), // = ( 92 x 165 ) mm = ( 3.62 x 6.50 ) in
'COMMENV_N8' => array( 278.640, 540.000 ), // = ( 98 x 191 ) mm = ( 3.87 x 7.50 ) in
'COMMENV_N9' => array( 278.640, 638.640 ), // = ( 98 x 225 ) mm = ( 3.87 x 8.87 ) in
'COMMENV_N10' => array( 296.640, 684.000 ), // = ( 105 x 241 ) mm = ( 4.12 x 9.50 ) in
'COMMENV_N11' => array( 324.000, 746.640 ), // = ( 114 x 263 ) mm = ( 4.50 x 10.37 ) in
'COMMENV_N12' => array( 342.000, 792.000 ), // = ( 121 x 279 ) mm = ( 4.75 x 11.00 ) in
'COMMENV_N14' => array( 360.000, 828.000 ), // = ( 127 x 292 ) mm = ( 5.00 x 11.50 ) in
// - Catalogue Envelopes
'CATENV_N1' => array( 432.000, 648.000 ), // = ( 152 x 229 ) mm = ( 6.00 x 9.00 ) in
'CATENV_N1_3/4' => array( 468.000, 684.000 ), // = ( 165 x 241 ) mm = ( 6.50 x 9.50 ) in
'CATENV_N2' => array( 468.000, 720.000 ), // = ( 165 x 254 ) mm = ( 6.50 x 10.00 ) in
'CATENV_N3' => array( 504.000, 720.000 ), // = ( 178 x 254 ) mm = ( 7.00 x 10.00 ) in
'CATENV_N6' => array( 540.000, 756.000 ), // = ( 191 x 267 ) mm = ( 7.50 x 10.50 ) in
'CATENV_N7' => array( 576.000, 792.000 ), // = ( 203 x 279 ) mm = ( 8.00 x 11.00 ) in
'CATENV_N8' => array( 594.000, 810.000 ), // = ( 210 x 286 ) mm = ( 8.25 x 11.25 ) in
'CATENV_N9_1/2' => array( 612.000, 756.000 ), // = ( 216 x 267 ) mm = ( 8.50 x 10.50 ) in
'CATENV_N9_3/4' => array( 630.000, 810.000 ), // = ( 222 x 286 ) mm = ( 8.75 x 11.25 ) in
'CATENV_N10_1/2' => array( 648.000, 864.000 ), // = ( 229 x 305 ) mm = ( 9.00 x 12.00 ) in
'CATENV_N12_1/2' => array( 684.000, 900.000 ), // = ( 241 x 318 ) mm = ( 9.50 x 12.50 ) in
'CATENV_N13_1/2' => array( 720.000, 936.000 ), // = ( 254 x 330 ) mm = ( 10.00 x 13.00 ) in
'CATENV_N14_1/4' => array( 810.000, 882.000 ), // = ( 286 x 311 ) mm = ( 11.25 x 12.25 ) in
'CATENV_N14_1/2' => array( 828.000, 1044.000 ), // = ( 292 x 368 ) mm = ( 11.50 x 14.50 ) in
// Japanese (JIS P 0138-61) Standard B-Series
'JIS_B0' => array( 2919.685, 4127.244 ), // = ( 1030 x 1456 ) mm = ( 40.55 x 57.32 ) in
'JIS_B1' => array( 2063.622, 2919.685 ), // = ( 728 x 1030 ) mm = ( 28.66 x 40.55 ) in
'JIS_B2' => array( 1459.843, 2063.622 ), // = ( 515 x 728 ) mm = ( 20.28 x 28.66 ) in
'JIS_B3' => array( 1031.811, 1459.843 ), // = ( 364 x 515 ) mm = ( 14.33 x 20.28 ) in
'JIS_B4' => array( 728.504, 1031.811 ), // = ( 257 x 364 ) mm = ( 10.12 x 14.33 ) in
'JIS_B5' => array( 515.906, 728.504 ), // = ( 182 x 257 ) mm = ( 7.17 x 10.12 ) in
'JIS_B6' => array( 362.835, 515.906 ), // = ( 128 x 182 ) mm = ( 5.04 x 7.17 ) in
'JIS_B7' => array( 257.953, 362.835 ), // = ( 91 x 128 ) mm = ( 3.58 x 5.04 ) in
'JIS_B8' => array( 181.417, 257.953 ), // = ( 64 x 91 ) mm = ( 2.52 x 3.58 ) in
'JIS_B9' => array( 127.559, 181.417 ), // = ( 45 x 64 ) mm = ( 1.77 x 2.52 ) in
'JIS_B10' => array( 90.709, 127.559 ), // = ( 32 x 45 ) mm = ( 1.26 x 1.77 ) in
'JIS_B11' => array( 62.362, 90.709 ), // = ( 22 x 32 ) mm = ( 0.87 x 1.26 ) in
'JIS_B12' => array( 45.354, 62.362 ), // = ( 16 x 22 ) mm = ( 0.63 x 0.87 ) in
// PA Series
'PA0' => array( 2381.102, 3174.803 ), // = ( 840 x 1120 ) mm = ( 33.07 x 44.09 ) in
'PA1' => array( 1587.402, 2381.102 ), // = ( 560 x 840 ) mm = ( 22.05 x 33.07 ) in
'PA2' => array( 1190.551, 1587.402 ), // = ( 420 x 560 ) mm = ( 16.54 x 22.05 ) in
'PA3' => array( 793.701, 1190.551 ), // = ( 280 x 420 ) mm = ( 11.02 x 16.54 ) in
'PA4' => array( 595.276, 793.701 ), // = ( 210 x 280 ) mm = ( 8.27 x 11.02 ) in
'PA5' => array( 396.850, 595.276 ), // = ( 140 x 210 ) mm = ( 5.51 x 8.27 ) in
'PA6' => array( 297.638, 396.850 ), // = ( 105 x 140 ) mm = ( 4.13 x 5.51 ) in
'PA7' => array( 198.425, 297.638 ), // = ( 70 x 105 ) mm = ( 2.76 x 4.13 ) in
'PA8' => array( 147.402, 198.425 ), // = ( 52 x 70 ) mm = ( 2.05 x 2.76 ) in
'PA9' => array( 99.213, 147.402 ), // = ( 35 x 52 ) mm = ( 1.38 x 2.05 ) in
'PA10' => array( 73.701, 99.213 ), // = ( 26 x 35 ) mm = ( 1.02 x 1.38 ) in
// Standard Photographic Print Sizes
'PASSPORT_PHOTO' => array( 99.213, 127.559 ), // = ( 35 x 45 ) mm = ( 1.38 x 1.77 ) in
'E' => array( 233.858, 340.157 ), // = ( 82 x 120 ) mm = ( 3.25 x 4.72 ) in
'L' => array( 252.283, 360.000 ), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in
'3R' => array( 252.283, 360.000 ), // = ( 89 x 127 ) mm = ( 3.50 x 5.00 ) in
'KG' => array( 289.134, 430.866 ), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in
'4R' => array( 289.134, 430.866 ), // = ( 102 x 152 ) mm = ( 4.02 x 5.98 ) in
'4D' => array( 340.157, 430.866 ), // = ( 120 x 152 ) mm = ( 4.72 x 5.98 ) in
'2L' => array( 360.000, 504.567 ), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in
'5R' => array( 360.000, 504.567 ), // = ( 127 x 178 ) mm = ( 5.00 x 7.01 ) in
'8P' => array( 430.866, 575.433 ), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in
'6R' => array( 430.866, 575.433 ), // = ( 152 x 203 ) mm = ( 5.98 x 7.99 ) in
'6P' => array( 575.433, 720.000 ), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in
'8R' => array( 575.433, 720.000 ), // = ( 203 x 254 ) mm = ( 7.99 x 10.00 ) in
'6PW' => array( 575.433, 864.567 ), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in
'S8R' => array( 575.433, 864.567 ), // = ( 203 x 305 ) mm = ( 7.99 x 12.01 ) in
'4P' => array( 720.000, 864.567 ), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in
'10R' => array( 720.000, 864.567 ), // = ( 254 x 305 ) mm = ( 10.00 x 12.01 ) in
'4PW' => array( 720.000, 1080.000 ), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in
'S10R' => array( 720.000, 1080.000 ), // = ( 254 x 381 ) mm = ( 10.00 x 15.00 ) in
'11R' => array( 790.866, 1009.134 ), // = ( 279 x 356 ) mm = ( 10.98 x 14.02 ) in
'S11R' => array( 790.866, 1224.567 ), // = ( 279 x 432 ) mm = ( 10.98 x 17.01 ) in
'12R' => array( 864.567, 1080.000 ), // = ( 305 x 381 ) mm = ( 12.01 x 15.00 ) in
'S12R' => array( 864.567, 1292.598 ), // = ( 305 x 456 ) mm = ( 12.01 x 17.95 ) in
// Common Newspaper Sizes
'NEWSPAPER_BROADSHEET' => array( 2125.984, 1700.787 ), // = ( 750 x 600 ) mm = ( 29.53 x 23.62 ) in
'NEWSPAPER_BERLINER' => array( 1332.283, 892.913 ), // = ( 470 x 315 ) mm = ( 18.50 x 12.40 ) in
'NEWSPAPER_TABLOID' => array( 1218.898, 793.701 ), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in
'NEWSPAPER_COMPACT' => array( 1218.898, 793.701 ), // = ( 430 x 280 ) mm = ( 16.93 x 11.02 ) in
// Business Cards
'CREDIT_CARD' => array( 153.014, 242.646 ), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
'BUSINESS_CARD' => array( 153.014, 242.646 ), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
'BUSINESS_CARD_ISO7810' => array( 153.014, 242.646 ), // = ( 54 x 86 ) mm = ( 2.13 x 3.37 ) in
'BUSINESS_CARD_ISO216' => array( 147.402, 209.764 ), // = ( 52 x 74 ) mm = ( 2.05 x 2.91 ) in
'BUSINESS_CARD_IT' => array( 155.906, 240.945 ), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
'BUSINESS_CARD_UK' => array( 155.906, 240.945 ), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
'BUSINESS_CARD_FR' => array( 155.906, 240.945 ), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
'BUSINESS_CARD_DE' => array( 155.906, 240.945 ), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
'BUSINESS_CARD_ES' => array( 155.906, 240.945 ), // = ( 55 x 85 ) mm = ( 2.17 x 3.35 ) in
'BUSINESS_CARD_CA' => array( 144.567, 252.283 ), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in
'BUSINESS_CARD_US' => array( 144.567, 252.283 ), // = ( 51 x 89 ) mm = ( 2.01 x 3.50 ) in
'BUSINESS_CARD_JP' => array( 155.906, 257.953 ), // = ( 55 x 91 ) mm = ( 2.17 x 3.58 ) in
'BUSINESS_CARD_HK' => array( 153.071, 255.118 ), // = ( 54 x 90 ) mm = ( 2.13 x 3.54 ) in
'BUSINESS_CARD_AU' => array( 155.906, 255.118 ), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
'BUSINESS_CARD_DK' => array( 155.906, 255.118 ), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
'BUSINESS_CARD_SE' => array( 155.906, 255.118 ), // = ( 55 x 90 ) mm = ( 2.17 x 3.54 ) in
'BUSINESS_CARD_RU' => array( 141.732, 255.118 ), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
'BUSINESS_CARD_CZ' => array( 141.732, 255.118 ), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
'BUSINESS_CARD_FI' => array( 141.732, 255.118 ), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
'BUSINESS_CARD_HU' => array( 141.732, 255.118 ), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
'BUSINESS_CARD_IL' => array( 141.732, 255.118 ), // = ( 50 x 90 ) mm = ( 1.97 x 3.54 ) in
// Billboards
'4SHEET' => array( 2880.000, 4320.000 ), // = ( 1016 x 1524 ) mm = ( 40.00 x 60.00 ) in
'6SHEET' => array( 3401.575, 5102.362 ), // = ( 1200 x 1800 ) mm = ( 47.24 x 70.87 ) in
'12SHEET' => array( 8640.000, 4320.000 ), // = ( 3048 x 1524 ) mm = (120.00 x 60.00 ) in
'16SHEET' => array( 5760.000, 8640.000 ), // = ( 2032 x 3048 ) mm = ( 80.00 x 120.00) in
'32SHEET' => array(11520.000, 8640.000 ), // = ( 4064 x 3048 ) mm = (160.00 x 120.00) in
'48SHEET' => array(17280.000, 8640.000 ), // = ( 6096 x 3048 ) mm = (240.00 x 120.00) in
'64SHEET' => array(23040.000, 8640.000 ), // = ( 8128 x 3048 ) mm = (320.00 x 120.00) in
'96SHEET' => array(34560.000, 8640.000 ), // = (12192 x 3048 ) mm = (480.00 x 120.00) in
// -- Old European Sizes
// - Old Imperial English Sizes
'EN_EMPEROR' => array( 3456.000, 5184.000 ), // = ( 1219 x 1829 ) mm = ( 48.00 x 72.00 ) in
'EN_ANTIQUARIAN' => array( 2232.000, 3816.000 ), // = ( 787 x 1346 ) mm = ( 31.00 x 53.00 ) in
'EN_GRAND_EAGLE' => array( 2070.000, 3024.000 ), // = ( 730 x 1067 ) mm = ( 28.75 x 42.00 ) in
'EN_DOUBLE_ELEPHANT' => array( 1926.000, 2880.000 ), // = ( 679 x 1016 ) mm = ( 26.75 x 40.00 ) in
'EN_ATLAS' => array( 1872.000, 2448.000 ), // = ( 660 x 864 ) mm = ( 26.00 x 34.00 ) in
'EN_COLOMBIER' => array( 1692.000, 2484.000 ), // = ( 597 x 876 ) mm = ( 23.50 x 34.50 ) in
'EN_ELEPHANT' => array( 1656.000, 2016.000 ), // = ( 584 x 711 ) mm = ( 23.00 x 28.00 ) in
'EN_DOUBLE_DEMY' => array( 1620.000, 2556.000 ), // = ( 572 x 902 ) mm = ( 22.50 x 35.50 ) in
'EN_IMPERIAL' => array( 1584.000, 2160.000 ), // = ( 559 x 762 ) mm = ( 22.00 x 30.00 ) in
'EN_PRINCESS' => array( 1548.000, 2016.000 ), // = ( 546 x 711 ) mm = ( 21.50 x 28.00 ) in
'EN_CARTRIDGE' => array( 1512.000, 1872.000 ), // = ( 533 x 660 ) mm = ( 21.00 x 26.00 ) in
'EN_DOUBLE_LARGE_POST' => array( 1512.000, 2376.000 ), // = ( 533 x 838 ) mm = ( 21.00 x 33.00 ) in
'EN_ROYAL' => array( 1440.000, 1800.000 ), // = ( 508 x 635 ) mm = ( 20.00 x 25.00 ) in
'EN_SHEET' => array( 1404.000, 1692.000 ), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in
'EN_HALF_POST' => array( 1404.000, 1692.000 ), // = ( 495 x 597 ) mm = ( 19.50 x 23.50 ) in
'EN_SUPER_ROYAL' => array( 1368.000, 1944.000 ), // = ( 483 x 686 ) mm = ( 19.00 x 27.00 ) in
'EN_DOUBLE_POST' => array( 1368.000, 2196.000 ), // = ( 483 x 775 ) mm = ( 19.00 x 30.50 ) in
'EN_MEDIUM' => array( 1260.000, 1656.000 ), // = ( 445 x 584 ) mm = ( 17.50 x 23.00 ) in
'EN_DEMY' => array( 1260.000, 1620.000 ), // = ( 445 x 572 ) mm = ( 17.50 x 22.50 ) in
'EN_LARGE_POST' => array( 1188.000, 1512.000 ), // = ( 419 x 533 ) mm = ( 16.50 x 21.00 ) in
'EN_COPY_DRAUGHT' => array( 1152.000, 1440.000 ), // = ( 406 x 508 ) mm = ( 16.00 x 20.00 ) in
'EN_POST' => array( 1116.000, 1386.000 ), // = ( 394 x 489 ) mm = ( 15.50 x 19.25 ) in
'EN_CROWN' => array( 1080.000, 1440.000 ), // = ( 381 x 508 ) mm = ( 15.00 x 20.00 ) in
'EN_PINCHED_POST' => array( 1062.000, 1332.000 ), // = ( 375 x 470 ) mm = ( 14.75 x 18.50 ) in
'EN_BRIEF' => array( 972.000, 1152.000 ), // = ( 343 x 406 ) mm = ( 13.50 x 16.00 ) in
'EN_FOOLSCAP' => array( 972.000, 1224.000 ), // = ( 343 x 432 ) mm = ( 13.50 x 17.00 ) in
'EN_SMALL_FOOLSCAP' => array( 954.000, 1188.000 ), // = ( 337 x 419 ) mm = ( 13.25 x 16.50 ) in
'EN_POTT' => array( 900.000, 1080.000 ), // = ( 318 x 381 ) mm = ( 12.50 x 15.00 ) in
// - Old Imperial Belgian Sizes
'BE_GRAND_AIGLE' => array( 1984.252, 2948.031 ), // = ( 700 x 1040 ) mm = ( 27.56 x 40.94 ) in
'BE_COLOMBIER' => array( 1757.480, 2409.449 ), // = ( 620 x 850 ) mm = ( 24.41 x 33.46 ) in
'BE_DOUBLE_CARRE' => array( 1757.480, 2607.874 ), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in
'BE_ELEPHANT' => array( 1746.142, 2182.677 ), // = ( 616 x 770 ) mm = ( 24.25 x 30.31 ) in
'BE_PETIT_AIGLE' => array( 1700.787, 2381.102 ), // = ( 600 x 840 ) mm = ( 23.62 x 33.07 ) in
'BE_GRAND_JESUS' => array( 1559.055, 2069.291 ), // = ( 550 x 730 ) mm = ( 21.65 x 28.74 ) in
'BE_JESUS' => array( 1530.709, 2069.291 ), // = ( 540 x 730 ) mm = ( 21.26 x 28.74 ) in
'BE_RAISIN' => array( 1417.323, 1842.520 ), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in
'BE_GRAND_MEDIAN' => array( 1303.937, 1714.961 ), // = ( 460 x 605 ) mm = ( 18.11 x 23.82 ) in
'BE_DOUBLE_POSTE' => array( 1233.071, 1601.575 ), // = ( 435 x 565 ) mm = ( 17.13 x 22.24 ) in
'BE_COQUILLE' => array( 1218.898, 1587.402 ), // = ( 430 x 560 ) mm = ( 16.93 x 22.05 ) in
'BE_PETIT_MEDIAN' => array( 1176.378, 1502.362 ), // = ( 415 x 530 ) mm = ( 16.34 x 20.87 ) in
'BE_RUCHE' => array( 1020.472, 1303.937 ), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in
'BE_PROPATRIA' => array( 977.953, 1218.898 ), // = ( 345 x 430 ) mm = ( 13.58 x 16.93 ) in
'BE_LYS' => array( 898.583, 1125.354 ), // = ( 317 x 397 ) mm = ( 12.48 x 15.63 ) in
'BE_POT' => array( 870.236, 1088.504 ), // = ( 307 x 384 ) mm = ( 12.09 x 15.12 ) in
'BE_ROSETTE' => array( 765.354, 983.622 ), // = ( 270 x 347 ) mm = ( 10.63 x 13.66 ) in
// - Old Imperial French Sizes
'FR_UNIVERS' => array( 2834.646, 3685.039 ), // = ( 1000 x 1300 ) mm = ( 39.37 x 51.18 ) in
'FR_DOUBLE_COLOMBIER' => array( 2551.181, 3571.654 ), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in
'FR_GRANDE_MONDE' => array( 2551.181, 3571.654 ), // = ( 900 x 1260 ) mm = ( 35.43 x 49.61 ) in
'FR_DOUBLE_SOLEIL' => array( 2267.717, 3401.575 ), // = ( 800 x 1200 ) mm = ( 31.50 x 47.24 ) in
'FR_DOUBLE_JESUS' => array( 2154.331, 3174.803 ), // = ( 760 x 1120 ) mm = ( 29.92 x 44.09 ) in
'FR_GRAND_AIGLE' => array( 2125.984, 3004.724 ), // = ( 750 x 1060 ) mm = ( 29.53 x 41.73 ) in
'FR_PETIT_AIGLE' => array( 1984.252, 2664.567 ), // = ( 700 x 940 ) mm = ( 27.56 x 37.01 ) in
'FR_DOUBLE_RAISIN' => array( 1842.520, 2834.646 ), // = ( 650 x 1000 ) mm = ( 25.59 x 39.37 ) in
'FR_JOURNAL' => array( 1842.520, 2664.567 ), // = ( 650 x 940 ) mm = ( 25.59 x 37.01 ) in
'FR_COLOMBIER_AFFICHE' => array( 1785.827, 2551.181 ), // = ( 630 x 900 ) mm = ( 24.80 x 35.43 ) in
'FR_DOUBLE_CAVALIER' => array( 1757.480, 2607.874 ), // = ( 620 x 920 ) mm = ( 24.41 x 36.22 ) in
'FR_CLOCHE' => array( 1700.787, 2267.717 ), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in
'FR_SOLEIL' => array( 1700.787, 2267.717 ), // = ( 600 x 800 ) mm = ( 23.62 x 31.50 ) in
'FR_DOUBLE_CARRE' => array( 1587.402, 2551.181 ), // = ( 560 x 900 ) mm = ( 22.05 x 35.43 ) in
'FR_DOUBLE_COQUILLE' => array( 1587.402, 2494.488 ), // = ( 560 x 880 ) mm = ( 22.05 x 34.65 ) in
'FR_JESUS' => array( 1587.402, 2154.331 ), // = ( 560 x 760 ) mm = ( 22.05 x 29.92 ) in
'FR_RAISIN' => array( 1417.323, 1842.520 ), // = ( 500 x 650 ) mm = ( 19.69 x 25.59 ) in
'FR_CAVALIER' => array( 1303.937, 1757.480 ), // = ( 460 x 620 ) mm = ( 18.11 x 24.41 ) in
'FR_DOUBLE_COURONNE' => array( 1303.937, 2040.945 ), // = ( 460 x 720 ) mm = ( 18.11 x 28.35 ) in
'FR_CARRE' => array( 1275.591, 1587.402 ), // = ( 450 x 560 ) mm = ( 17.72 x 22.05 ) in
'FR_COQUILLE' => array( 1247.244, 1587.402 ), // = ( 440 x 560 ) mm = ( 17.32 x 22.05 ) in
'FR_DOUBLE_TELLIERE' => array( 1247.244, 1927.559 ), // = ( 440 x 680 ) mm = ( 17.32 x 26.77 ) in
'FR_DOUBLE_CLOCHE' => array( 1133.858, 1700.787 ), // = ( 400 x 600 ) mm = ( 15.75 x 23.62 ) in
'FR_DOUBLE_POT' => array( 1133.858, 1757.480 ), // = ( 400 x 620 ) mm = ( 15.75 x 24.41 ) in
'FR_ECU' => array( 1133.858, 1474.016 ), // = ( 400 x 520 ) mm = ( 15.75 x 20.47 ) in
'FR_COURONNE' => array( 1020.472, 1303.937 ), // = ( 360 x 460 ) mm = ( 14.17 x 18.11 ) in
'FR_TELLIERE' => array( 963.780, 1247.244 ), // = ( 340 x 440 ) mm = ( 13.39 x 17.32 ) in
'FR_POT' => array( 878.740, 1133.858 ), // = ( 310 x 400 ) mm = ( 12.20 x 15.75 ) in
);

View File

@@ -0,0 +1,129 @@
<?php
/**
* EAN for WooCommerce - Advanced Section Settings
*
* @version 4.7.3
* @since 2.2.9
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Advanced' ) ) :
class Alg_WC_EAN_Settings_Advanced extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 2.2.9
* @since 2.2.9
*/
function __construct() {
$this->id = 'advanced';
$this->desc = __( 'Advanced', 'ean-for-woocommerce' );
parent::__construct();
}
/**
* get_settings.
*
* @version 4.7.3
* @since 2.2.9
*
* @todo (dev) Import/Export: move to "Tools", and/or add dashicons?
* @todo (desc) `alg_wc_ean_meta_key`
* @todo (desc) `alg_wc_ean_js_variations_form_closest`: better desc
*/
function get_settings() {
return array(
array(
'title' => __( 'Advanced Options', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_advanced_options',
),
array(
'title' => __( 'Meta key', 'ean-for-woocommerce' ),
'desc' => sprintf( __( 'Default: %s', 'ean-for-woocommerce' ), '<code>_alg_ean</code>' ),
'id' => 'alg_wc_ean_meta_key',
'default' => '_alg_ean',
'type' => 'text',
'custom_attributes' => array( 'required' => 'required' ),
),
array(
'title' => __( 'Force remote image', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Forces remote images in Barcodes > Order items table > Pages.', 'ean-for-woocommerce' ) . ' ' .
__( '<strong>Please note</strong> that this option won\'t work on <code>localhost</code> environment.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_order_items_table_barcode_force_remote_img',
'default' => 'no',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_advanced_options',
),
array(
'title' => __( 'JavaScript Variation Options', 'ean-for-woocommerce' ),
'desc' => sprintf( __( 'This is used only if "%s" option is set to "%s".', 'ean-for-woocommerce' ),
__( 'Variable products: Position in variation', 'ean-for-woocommerce' ), __( 'Product meta', 'ean-for-woocommerce' ) ) . ' ' .
__( 'Leave at the default value if unsure.', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_advanced_js_options',
),
array(
'title' => __( 'Variations form', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_js_variations_form',
'default' => '.variations_form',
'type' => 'text',
),
array(
'title' => __( 'Closest container', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_js_variations_form_closest',
'default' => '.summary',
'type' => 'text',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_advanced_js_options',
),
array(
'title' => __( 'Export/Import/Reset Plugin Settings', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_export_import_settings_options',
),
array(
'title' => __( 'Export', 'ean-for-woocommerce' ),
'desc' => __( 'Export all settings', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Check the box and "Save changes" to export.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_export_settings',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Import', 'ean-for-woocommerce' ),
'desc' => __( 'Choose file and "Save changes" to import.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_import_settings',
'type' => 'alg_wc_ean_file',
),
array(
'title' => __( 'Reset', 'ean-for-woocommerce' ),
'desc' => __( 'Reset all settings', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Check the box and "Save changes" to reset.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_reset_settings',
'default' => 'no',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_export_import_settings_options',
),
);
}
}
endif;
return new Alg_WC_EAN_Settings_Advanced();

View File

@@ -0,0 +1,192 @@
<?php
/**
* EAN for WooCommerce - Barcodes - Compatibility Section Settings
*
* @version 4.2.0
* @since 3.8.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Barcodes_Compatibility' ) ) :
class Alg_WC_EAN_Settings_Barcodes_Compatibility extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 3.8.0
* @since 3.8.0
*/
function __construct( $dim ) {
$this->dim = $dim;
$this->dim_suffix = ( '1d' === $this->dim ? '' : '_2d' );
$this->id = ( '1d' === $this->dim ? 'barcodes' : 'barcodes_2d' ) . '_compatibility';
$this->desc = ( '1d' === $this->dim ? __( 'Barcodes', 'ean-for-woocommerce' ) : __( '2D Barcodes', 'ean-for-woocommerce' ) ) . ' > ' . __( 'Compatibility', 'ean-for-woocommerce' );
parent::__construct();
}
/**
* get_settings.
*
* @version 4.2.0
* @since 3.8.0
*/
function get_settings() {
$settings = array(
array(
'title' => __( 'Plugin Compatibility Options', 'ean-for-woocommerce' ),
'desc' => sprintf( __( '"%s" option must be enabled.', 'ean-for-woocommerce' ),
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=alg_wc_ean&section=' . ( '1d' === $this->dim ? 'barcodes' : 'barcodes_2d' ) ) . '">' .
( '1d' === $this->dim ? __( 'Barcodes', 'ean-for-woocommerce' ) : __( '2D Barcodes', 'ean-for-woocommerce' ) ) . ' > ' . __( 'Enable section', 'ean-for-woocommerce' ) .
'</a>' ),
'type' => 'title',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_compatibility_options",
),
array(
'title' => __( 'Print Invoice & Delivery Notes for WooCommerce', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Show barcode image in PDF documents of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="' . 'https://wordpress.org/plugins/woocommerce-delivery-notes/' . '">' .
__( 'Print Invoice & Delivery Notes for WooCommerce', 'ean-for-woocommerce' ) . '</a>' ),
'id' => "alg_wc_ean_wcdn_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'WooCommerce PDF Invoices & Packing Slips', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Show barcode image in PDF documents of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="' . 'https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/' . '">' .
__( 'WooCommerce PDF Invoices & Packing Slips', 'ean-for-woocommerce' ) . '</a>' ),
'id' => "alg_wc_ean_wpo_wcpdf_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Content', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wpo_wcpdf_barcode_options{$this->dim_suffix}[content]",
'default' => '<div class="ean_wrapper' . $this->dim_suffix . '">[alg_wc_ean_barcode' . $this->dim_suffix . ']</div>',
'type' => 'textarea',
),
array(
'desc' => __( 'Position', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wpo_wcpdf_barcode_position{$this->dim_suffix}",
'default' => 'wpo_wcpdf_after_item_meta',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'wpo_wcpdf_before_item_meta' => __( 'Before item meta', 'ean-for-woocommerce' ),
'wpo_wcpdf_after_item_meta' => __( 'After item meta', 'ean-for-woocommerce' ),
),
),
array(
'title' => __( 'WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Show barcode image in PDF documents of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="' . 'https://wordpress.org/plugins/print-invoices-packing-slip-labels-for-woocommerce/' . '">' .
__( 'WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels', 'ean-for-woocommerce' ) . '</a>' ),
'id' => "alg_wc_ean_wt_pklist_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Content', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wt_pklist_barcode_options{$this->dim_suffix}[content]",
'default' => "<p>[alg_wc_ean_barcode{$this->dim_suffix}]</p>",
'type' => 'textarea',
),
array(
'desc' => __( 'Position', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wt_pklist_barcode_options{$this->dim_suffix}[position]",
'default' => 'after_product_meta',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'before_product_name' => __( 'Before item name', 'ean-for-woocommerce' ),
'after_product_name' => __( 'After item name', 'ean-for-woocommerce' ),
'before_product_meta' => __( 'Before item meta', 'ean-for-woocommerce' ),
'after_product_meta' => __( 'After item meta', 'ean-for-woocommerce' ),
'column' => __( 'As a separate column', 'ean-for-woocommerce' ),
),
),
array(
'desc' => __( 'Documents', 'ean-for-woocommerce' ) . '<br>' .
sprintf( __( 'Can be a comma-separated list, e.g.: %s.', 'ean-for-woocommerce' ),
'<code>' . implode( ',', array( 'invoice', 'packinglist', 'deliverynote', 'dispatchlabel' ) ) . '</code>' ),
'desc_tip' => __( 'Leave empty to include in all documents.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wt_pklist_barcode_options{$this->dim_suffix}[documents]",
'default' => '',
'type' => 'text',
),
array(
'desc' => __( 'Column title', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Used only if the "Position" option is set to the "As a separate column".', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wt_pklist_barcode_options{$this->dim_suffix}[column_title]",
'default' => __( 'Barcode', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'desc' => sprintf( __( 'Column HTML %s', 'ean-for-woocommerce' ), '<code>class</code>' ),
'desc_tip' => __( 'Used only if the "Position" option is set to the "As a separate column".', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wt_pklist_barcode_options{$this->dim_suffix}[column_class]",
'default' => 'wfte_product_table_head_ean wfte_text_center',
'type' => 'text',
),
array(
'desc' => sprintf( __( 'Column HTML %s', 'ean-for-woocommerce' ), '<code>style</code>' ),
'desc_tip' => __( 'Used only if the "Position" option is set to the "As a separate column".', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wt_pklist_barcode_options{$this->dim_suffix}[column_style]",
'default' => '',
'type' => 'text',
),
array(
'title' => __( 'WooCommerce Customer / Order / Coupon Export', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will add %s column to the order items export of the %s plugin.', 'ean-for-woocommerce' ),
"<code>item_barcode{$this->dim_suffix}</code>", '<a target="_blank" href="https://woocommerce.com/products/ordercustomer-csv-export/">' . __( 'WooCommerce Customer / Order / Coupon Export', 'ean-for-woocommerce' ) . '</a>' ),
'id' => "alg_wc_ean_wc_customer_order_export_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Content', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_wc_customer_order_export_content_barcode{$this->dim_suffix}",
'default' => '[alg_wc_ean_barcode' . $this->dim_suffix . '_base64 before="data:image/png;base64,"]',
'type' => 'textarea',
'css' => 'width:100%;',
),
array(
'title' => __( 'Dokan', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will show barcode in vendor product form of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="https://wordpress.org/plugins/dokan-lite/">' . __( 'Dokan', 'ean-for-woocommerce' ) . '</a>' ),
'id' => "alg_wc_ean_dokan_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Title', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_dokan_title_barcode{$this->dim_suffix}",
'default' => __( 'Barcode', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'desc' => __( 'Content', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_dokan_content_barcode{$this->dim_suffix}",
'default' => "[alg_wc_ean_barcode{$this->dim_suffix}]",
'type' => 'textarea',
),
array(
'type' => 'sectionend',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_compatibility_options",
),
);
return $settings;
}
}
endif;

View File

@@ -0,0 +1,291 @@
<?php
/**
* EAN for WooCommerce - Barcodes Section Settings
*
* @version 4.5.0
* @since 2.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Barcodes' ) ) :
class Alg_WC_EAN_Settings_Barcodes extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 3.6.0
* @since 2.0.0
*/
function __construct( $dim ) {
$this->dim = $dim;
$this->dim_suffix = ( '1d' === $this->dim ? '' : '_2d' );
$this->id = ( '1d' === $this->dim ? 'barcodes' : 'barcodes_2d' );
$this->desc = ( '1d' === $this->dim ? __( 'Barcodes', 'ean-for-woocommerce' ) : __( '2D Barcodes', 'ean-for-woocommerce' ) );
parent::__construct();
}
/**
* get_settings.
*
* @version 4.5.0
* @since 2.0.0
*
* @todo (desc) Enable section: better desc
* @todo (desc) `alg_wc_ean_order_items_table_barcode`: "... *may* not work..."?
* @todo (dev) `alg_wc_ean_backend_column_barcode_data[]`?
* @todo (desc) `alg_wc_ean_backend_column_barcode_template`: better desc?
* @todo (dev) Barcode type: `1d`: `EAN14`?
* @todo (dev) Barcode type: add all types from https://github.com/tecnickcom/TCPDF/blob/6.3.5/tcpdf_barcodes_2d.php#L66, i.e., `QRCODE` and `PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6` (last one maybe as an additional "Custom type" option?)
*/
function get_settings() {
$settings = array(
array(
'title' => sprintf( __( '%s Options', 'ean-for-woocommerce' ), $this->desc ),
'type' => 'title',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_options",
),
array(
'title' => $this->desc,
'desc' => '<strong>' . __( 'Enable section', 'ean-for-woocommerce' ) . '</strong>',
'desc_tip' => $this->pro_msg(),
'id' => "alg_wc_ean_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
'custom_attributes' => apply_filters( 'alg_wc_ean_settings', array( 'disabled' => 'disabled' ) ),
),
array(
'title' => __( 'Admin product edit page', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Show barcode image on admin product edit page.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_backend_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Admin products list column', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Add "Barcode" column to %s.', 'ean-for-woocommerce' ),
'<a href="' . admin_url( 'edit.php?post_type=product' ) . '">' . __( 'admin products list', 'ean-for-woocommerce' ) . '</a>' ),
'id' => "alg_wc_ean_backend_column_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Column title', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_backend_column_barcode_title{$this->dim_suffix}",
'default' => ( '1d' === $this->dim ? __( 'Barcode', 'ean-for-woocommerce' ) : __( '2D barcode', 'ean-for-woocommerce' ) ),
'type' => 'text',
),
array(
'desc' => __( 'Column template', 'ean-for-woocommerce' ) . '<br>' .
sprintf( __( 'You should use %s shortcode here.', 'ean-for-woocommerce' ), '<code>[alg_wc_ean_barcode' . $this->dim_suffix . ']</code>' ),
'id' => "alg_wc_ean_backend_column_barcode_template{$this->dim_suffix}",
'default' => '[alg_wc_ean_barcode' . $this->dim_suffix . ' content="ean" w="' . ( '1d' === $this->dim ? 1 : 1 ) . '" h="' . ( '1d' === $this->dim ? 15 : 1 ) . '" children="yes"]',
'type' => 'textarea',
'css' => 'width:100%;',
),
array(
'title' => __( 'Single product page', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Show barcode image on single product page on frontend.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_frontend_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Variable products: Position in variation', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_frontend_variation_position_barcode{$this->dim_suffix}",
'default' => 'product_meta',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'product_meta' => __( 'Product meta', 'ean-for-woocommerce' ),
'variation_description' => __( 'Description', 'ean-for-woocommerce' ),
),
),
array(
'title' => __( 'Shop pages', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Show barcode on shop (e.g., category) pages on frontend.', 'ean-for-woocommerce' ) . ' ' . $this->variable_products_note(),
'id' => "alg_wc_ean_frontend_loop_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Cart', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Show barcode on cart page on frontend.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_frontend_cart_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Cart template', 'ean-for-woocommerce' ) . '<br>' .
sprintf( __( 'You should use %s shortcode here.', 'ean-for-woocommerce' ), '<code>[alg_wc_ean_barcode' . $this->dim_suffix . ']</code>' ),
'id' => "alg_wc_ean_frontend_cart_barcode_template{$this->dim_suffix}",
'default' => '[alg_wc_ean_barcode' . $this->dim_suffix .
' before=\'<span class="sku_wrapper ean_barcode' . $this->dim_suffix . '_wrapper"><span class="ean_barcode' . $this->dim_suffix . '">\'' .
' after=\'</span></span>\']',
'type' => 'textarea',
'css' => 'width:100%;',
),
array(
'type' => 'sectionend',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_options",
),
array(
'title' => __( 'Orders & Emails', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_orders_options",
),
array(
'title' => __( 'Orders', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Show barcode image on admin order edit page.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_order_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Template', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_order_template_barcode{$this->dim_suffix}",
'default' => "<p>[alg_wc_ean_barcode{$this->dim_suffix}]</p>",
'type' => 'textarea',
'css' => 'width:100%;',
),
array(
'title' => __( 'Order items table', 'ean-for-woocommerce' ),
'desc' => __( 'Pages', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Show barcode image in order items table on <strong>pages</strong>.', 'ean-for-woocommerce' ) . ' ' .
__( 'E.g.: "thank you" (i.e., "order received") page, "view order" page (in "my account").', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_order_items_table_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Emails', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Show barcode image in order items table in <strong>emails</strong>.', 'ean-for-woocommerce' ) . ' ' .
__( 'You can limit it to the specific emails in the "Emails list" option below.', 'ean-for-woocommerce' ) . '<br>' .
__( '<strong>Please note</strong> that this option won\'t work on <code>localhost</code> environment.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_order_items_table_emails_barcode{$this->dim_suffix}",
'default' => get_option( "alg_wc_ean_order_items_table_barcode{$this->dim_suffix}", 'no' ), // for the backward compatibility
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'desc' => __( 'Emails list', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Leave empty to add to all emails.', 'ean-for-woocommerce' ) . ' ' .
__( 'Ignored unless the "Emails" option above is enabled.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_order_items_table_emails_list_barcode{$this->dim_suffix}",
'default' => array(),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => $this->get_wc_emails(),
),
array(
'type' => 'sectionend',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_orders_options",
),
array(
'title' => __( 'REST API', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_rest_api_options",
),
array(
'title' => __( 'Products', 'ean-for-woocommerce' ),
'desc' => __( 'Add barcode (base64) to each product object in REST API responses', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'E.g.: %s', 'ean-for-woocommerce' ), '<code>https://example.com/wp-json/wc/v3/products/123</code>' ),
'id' => "alg_wc_ean_rest_api_product_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Orders', 'ean-for-woocommerce' ),
'desc' => __( 'Add barcode (base64) to each order object in REST API responses', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'E.g.: %s', 'ean-for-woocommerce' ), '<code>https://example.com/wp-json/wc/v3/orders/465</code>' ),
'id' => "alg_wc_ean_rest_api_order_barcode{$this->dim_suffix}",
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Template', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Used for both "Products" and "Orders" REST API responses.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_rest_api_product_template_barcode{$this->dim_suffix}",
'default' => '[alg_wc_ean_barcode' . $this->dim_suffix . '_base64 before="data:image/png;base64,"]',
'type' => 'textarea',
'css' => 'width:100%;',
),
array(
'type' => 'sectionend',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_rest_api_options",
),
);
$settings = array_merge( $settings, array(
array(
'title' => __( 'Advanced Barcodes Options', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_advanced_options",
),
array(
'title' => __( 'Barcode type', 'ean-for-woocommerce' ),
'desc' => ( '2d' === $this->dim ? '' : sprintf( __( 'If set to "Automatic", will use the barcode type based on EAN type, i.e., %s for EAN-8, %s for UPC-A, %s for EAN-13, ISBN-13 and JAN, and %s for all other types.', 'ean-for-woocommerce' ),
'<code>EAN-8</code>', '<code>UPC-A</code>', '<code>EAN-13</code>', '<code>CODE 128</code>' ) ),
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_barcode_type",
'default' => ( '2d' === $this->dim ? 'QRCODE,L' : 'AUTO' ),
'type' => 'select',
'class' => 'chosen_select',
'options' => ( '2d' === $this->dim ?
array(
'QRCODE,L' => __( 'QR code: Low error correction', 'ean-for-woocommerce' ),
'QRCODE,M' => __( 'QR code: Medium error correction', 'ean-for-woocommerce' ),
'QRCODE,Q' => __( 'QR code: Better error correction', 'ean-for-woocommerce' ),
'QRCODE,H' => __( 'QR code: Best error correction', 'ean-for-woocommerce' ),
'DATAMATRIX' => __( 'Datamatrix (ISO/IEC 16022)', 'ean-for-woocommerce' ),
'PDF417' => __( 'PDF417 (ISO/IEC 15438:2006)', 'ean-for-woocommerce' ),
) :
array(
'AUTO' => __( 'Automatic', 'ean-for-woocommerce' ),
'EAN8' => 'EAN-8',
'UPCA' => 'UPC-A',
'EAN13' => 'EAN-13',
'C128' => 'CODE 128',
)
),
),
array(
'title' => __( 'Suppress errors', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ) . ' (' . __( 'recommended', 'ean-for-woocommerce' ) . ')',
'desc_tip' => __( 'Suppress PHP errors when generating barcode.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_suppress_errors_barcode{$this->dim_suffix}",
'default' => 'yes',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_advanced_options",
),
) );
$settings = array_merge( $settings, array(
array(
'title' => __( 'Notes', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-info"></span> ' . sprintf( __( 'You can also output barcode with %s shortcode.', 'ean-for-woocommerce' ),
"<code>[alg_wc_ean_barcode{$this->dim_suffix}]</code>" ),
'type' => 'title',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_notes",
),
array(
'type' => 'sectionend',
'id' => "alg_wc_ean_barcode{$this->dim_suffix}_notes",
),
) );
return $settings;
}
}
endif;

View File

@@ -0,0 +1,294 @@
<?php
/**
* EAN for WooCommerce - Compatibility Section Settings
*
* @version 4.7.8
* @since 2.2.9
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Compatibility' ) ) :
class Alg_WC_EAN_Settings_Compatibility extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 2.2.9
* @since 2.2.9
*/
function __construct() {
$this->id = 'compatibility';
$this->desc = __( 'Compatibility', 'ean-for-woocommerce' );
parent::__construct();
}
/**
* get_settings.
*
* @version 4.7.8
* @since 2.2.9
*
* @todo (dev) `alg_wc_ean_wcfm_hints`: better default value?
* @todo (desc) `alg_wc_ean_wcfm_add_generate_button`: better desc?
*/
function get_settings() {
return array(
array(
'title' => __( 'Plugin Compatibility Options', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_plugin_compatibility_options',
),
array(
'title' => __( 'Google Listings & Ads', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will add EAN to the product data of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="' . 'https://wordpress.org/plugins/google-listings-and-ads/' . '">' .
__( 'Google Listings & Ads', 'ean-for-woocommerce' ) . '</a>' ) . '<br>' .
sprintf( __( 'After enabling the checkbox, go to "Marketing > Google Listings & Ads > Attributes > Create attribute rule", select the "GTIN" attribute, and then select %s in the "Use value from existing product field" dropdown box.', 'ean-for-woocommerce' ),
'<code>' . alg_wc_ean()->core->ean_key . '</code>' ) . '<br>' .
( defined( 'WC_GLA_VERSION' ) ? sprintf( __( 'You may also want to "Sync All Products with Google Merchant Center" on the %s.', 'ean-for-woocommerce' ),
'<a href="' . admin_url( 'admin.php?page=connection-test-admin-page' ) . '">' . __( 'Google Listings & Ads connection testing page', 'ean-for-woocommerce' ) . '</a>' ) : '' ),
'id' => 'alg_wc_ean_gla',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Point of Sale for WooCommerce', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will add EAN to the product search of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="' . 'https://woocommerce.com/products/point-of-sale-for-woocommerce/' . '">' .
__( 'Point of Sale for WooCommerce', 'ean-for-woocommerce' ) . '</a>' ) . '<br>' .
__( '<strong>Please note</strong> that "WooCommerce > Settings > EAN > General > Search" option must be enabled as well.', 'ean-for-woocommerce' ) . '<br>' .
__( '<strong>Alternatively</strong> you can add "EAN" to the "Scanning Fields" and "Product SKU" to the "Search Includes" options in "Point of Sale > Settings > Register".', 'ean-for-woocommerce' ) . '<br>' .
'* ' . __( 'To enable searching with a scanner, add "EAN" field to the "Scanning Fields" option in "Point of Sale > Settings > Register".', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wc_pos_search',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Print Invoice & Delivery Notes for WooCommerce', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will show EAN in PDF documents of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="' . 'https://wordpress.org/plugins/woocommerce-delivery-notes/' . '">' .
__( 'Print Invoice & Delivery Notes for WooCommerce', 'ean-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_ean_wcdn',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'WooCommerce PDF Invoices & Packing Slips', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will show EAN in PDF documents of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="' . 'https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/' . '">' .
__( 'WooCommerce PDF Invoices & Packing Slips', 'ean-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_ean_wpo_wcpdf',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Content', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Available placeholder: %s.', 'ean-for-woocommerce' ), '%ean%' ),
'id' => 'alg_wc_ean_wpo_wcpdf_options[content]',
'default' => '<dl class="meta">' .
'<dt class="ean">' . esc_html( get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) ) . ':' . '</dt>' .
'<dd class="ean">' . '%ean%' . '</dd>' .
'</dl>',
'type' => 'textarea',
),
array(
'desc' => __( 'Position', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wpo_wcpdf_position',
'default' => 'wpo_wcpdf_after_item_meta',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'wpo_wcpdf_before_item_meta' => __( 'Before item meta', 'ean-for-woocommerce' ),
'wpo_wcpdf_after_item_meta' => __( 'After item meta', 'ean-for-woocommerce' ),
),
),
array(
'title' => __( 'WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will show EAN in PDF documents of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="' . 'https://wordpress.org/plugins/print-invoices-packing-slip-labels-for-woocommerce/' . '">' .
__( 'WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels', 'ean-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_ean_wt_pklist',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Content', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wt_pklist_options[content]',
'default' => '<p>EAN: [alg_wc_ean]</p>',
'type' => 'textarea',
),
array(
'desc' => __( 'Position', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wt_pklist_options[position]',
'default' => 'after_product_meta',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'before_product_name' => __( 'Before item name', 'ean-for-woocommerce' ),
'after_product_name' => __( 'After item name', 'ean-for-woocommerce' ),
'before_product_meta' => __( 'Before item meta', 'ean-for-woocommerce' ),
'after_product_meta' => __( 'After item meta', 'ean-for-woocommerce' ),
'column' => __( 'As a separate column', 'ean-for-woocommerce' ),
),
),
array(
'desc' => __( 'Documents', 'ean-for-woocommerce' ) . '<br>' .
sprintf( __( 'Can be a comma-separated list, e.g.: %s.', 'ean-for-woocommerce' ),
'<code>' . implode( ',', array( 'invoice', 'packinglist', 'deliverynote', 'dispatchlabel' ) ) . '</code>' ),
'desc_tip' => __( 'Leave empty to include in all documents.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wt_pklist_options[documents]',
'default' => '',
'type' => 'text',
),
array(
'desc' => __( 'Column title', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Used only if the "Position" option is set to the "As a separate column".', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wt_pklist_options[column_title]',
'default' => __( 'EAN', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'desc' => sprintf( __( 'Column HTML %s', 'ean-for-woocommerce' ), '<code>class</code>' ),
'desc_tip' => __( 'Used only if the "Position" option is set to the "As a separate column".', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wt_pklist_options[column_class]',
'default' => 'wfte_product_table_head_ean wfte_text_center',
'type' => 'text',
),
array(
'desc' => sprintf( __( 'Column HTML %s', 'ean-for-woocommerce' ), '<code>style</code>' ),
'desc_tip' => __( 'Used only if the "Position" option is set to the "As a separate column".', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wt_pklist_options[column_style]',
'default' => '',
'type' => 'text',
),
array(
'title' => __( 'WooCommerce Customer / Order / Coupon Export', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will add %s column to the order items export of the %s plugin.', 'ean-for-woocommerce' ),
'<code>item_ean</code>', '<a target="_blank" href="https://woocommerce.com/products/ordercustomer-csv-export/">' . __( 'WooCommerce Customer / Order / Coupon Export', 'ean-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_ean_wc_customer_order_export',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Dokan', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will show EAN in vendor product form of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="https://wordpress.org/plugins/dokan-lite/">' . __( 'Dokan', 'ean-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_ean_dokan',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Required', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_dokan_required',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => sprintf( __( 'Required HTML, e.g.: %s', 'ean-for-woocommerce' ),
'<code>' . esc_html( '&amp;nbsp;<abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>' ) . '</code>' ),
'id' => 'alg_wc_ean_dokan_required_html',
'default' => '',
'type' => 'textarea',
),
array(
'desc' => __( 'Title', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_dokan_title',
'default' => __( 'EAN', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'desc' => __( 'Placeholder', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_dokan_placeholder',
'default' => __( 'Product EAN...', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'desc' => __( 'Description', 'ean-for-woocommerce' ) . '<br>' .
sprintf( __( 'You can use HTML and shortcodes here, e.g.: %s', 'ean-for-woocommerce' ),
'<code>' . esc_html( '<div>[alg_wc_ean_is_valid] | [alg_wc_ean_is_unique]</div>' ) . '</code>' ),
'id' => 'alg_wc_ean_dokan_desc',
'default' => '',
'type' => 'textarea',
'css' => 'height:100px;',
),
array(
'title' => __( 'WCFM', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will show EAN in product forms of the %s and %s plugins.', 'ean-for-woocommerce' ),
'<a target="_blank" href="https://wordpress.org/plugins/wc-frontend-manager/">' . __( 'WCFM', 'ean-for-woocommerce' ) . '</a>',
'<a target="_blank" href="https://wordpress.org/plugins/wc-multivendor-marketplace/">' . __( 'WCFM Marketplace', 'ean-for-woocommerce' ) . '</a>' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wcfm',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Title', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wcfm_title',
'default' => __( 'EAN', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'desc' => __( 'Placeholder', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wcfm_placeholder',
'default' => __( 'Product EAN...', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'desc' => __( 'Hints', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_wcfm_hints',
'default' => __( 'The International Article Number (also known as European Article Number or EAN) is a standard describing a barcode symbology and numbering system used in global trade to identify a specific retail product type, in a specific packaging configuration, from a specific manufacturer.', 'ean-for-woocommerce' ),
'type' => 'textarea',
'css' => 'height:110px;',
),
array(
'desc' => __( 'Add "Generate" button', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will add "Generate %s" button to the vendor product edit pages.', 'ean-for-woocommerce' ),
get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) ),
'id' => 'alg_wc_ean_wcfm_add_generate_button',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'MultiVendorX', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will show EAN in vendor product form of the %s plugin.', 'ean-for-woocommerce' ),
'<a target="_blank" href="https://wordpress.org/plugins/dc-woocommerce-multi-vendor/">' . __( 'MultiVendorX', 'ean-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_ean_mvx',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Title', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_mvx_title',
'default' => __( 'EAN:', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'desc' => __( 'Placeholder', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_mvx_placeholder',
'default' => '',
'type' => 'text',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_plugin_compatibility_options',
),
);
}
}
endif;
return new Alg_WC_EAN_Settings_Compatibility();

View File

@@ -0,0 +1,126 @@
<?php
/**
* EAN for WooCommerce - Extra Field Section Settings
*
* @version 4.7.6
* @since 4.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Extra_Field' ) ) :
class Alg_WC_EAN_Settings_Extra_Field extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 4.0.0
* @since 4.0.0
*/
function __construct( $num ) {
$this->num = $num;
$this->id = 'extra_field_' . $this->num;
$this->desc = $this->get_desc();
parent::__construct();
}
/**
* get_desc.
*
* @version 4.0.0
* @since 4.0.0
*
* @todo (dev) this is (almost) duplicated in `Alg_WC_EAN_Extra_Field::get_name()`
*/
function get_desc() {
$name = get_option( 'alg_wc_ean_extra_field_name', array() );
return ( isset( $name[ $this->num ] ) && '' !== $name[ $this->num ] ? $name[ $this->num ] : sprintf( __( 'Extra field #%d', 'ean-for-woocommerce' ), $this->num ) );
}
/**
* get_settings.
*
* @version 4.7.6
* @since 4.0.0
*/
function get_settings() {
$settings = array(
array(
'title' => sprintf( __( '%s Options', 'ean-for-woocommerce' ), $this->desc ),
'type' => 'title',
'id' => 'alg_wc_ean_extra_field_' . $this->num . '_options',
),
array(
'title' => $this->get_desc(),
'desc' => '<strong>' . __( 'Enable field', 'ean-for-woocommerce' ) . '</strong>',
'desc_tip' => $this->pro_msg( 'enable this field' ),
'type' => 'checkbox',
'id' => "alg_wc_ean_extra_field_enabled[{$this->num}]",
'default' => 'no',
'custom_attributes' => apply_filters( 'alg_wc_ean_settings', array( 'disabled' => 'disabled' ) ),
),
array(
'title' => __( 'Title', 'ean-for-woocommerce' ),
'desc' => sprintf( __( 'For example: %s', 'ean-for-woocommerce' ), '<code>MPN</code>' ),
'type' => 'text',
'id' => "alg_wc_ean_extra_field_name[{$this->num}]",
'default' => sprintf( __( 'Extra field #%d', 'ean-for-woocommerce' ), $this->num ),
'custom_attributes' => array( 'required' => 'required' ),
),
array(
'title' => __( 'Meta key', 'ean-for-woocommerce' ),
'desc' => sprintf( __( 'For example: %s', 'ean-for-woocommerce' ), '<code>mpn</code>' ),
'type' => 'text',
'id' => "alg_wc_ean_extra_field_key[{$this->num}]",
'default' => sprintf( 'extra_field_%d', $this->num ),
'custom_attributes' => array( 'required' => 'required' ),
),
array(
'title' => __( 'Admin product search', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_extra_field_backend_search[{$this->num}]",
'desc_tip' => __( 'This will enable searching by the field in admin area.', 'ean-for-woocommerce' ),
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Single product page', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will show the field on single product page on frontend.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_extra_field_frontend[{$this->num}]",
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Search', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will enable searching by the field on the frontend.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_extra_field_frontend_search[{$this->num}]",
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Product structured data', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_extra_field_structured_data_product[{$this->num}]",
'desc_tip' => __( 'This will add the field to the product structured data, e.g., for Google Search Console.', 'ean-for-woocommerce' ),
'default' => 'yes',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_extra_field_' . $this->num . '_options',
),
);
return $settings;
}
}
endif;

View File

@@ -0,0 +1,95 @@
<?php
/**
* EAN for WooCommerce - Extra Fields Section Settings
*
* @version 4.7.6
* @since 4.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Extra_Fields' ) ) :
class Alg_WC_EAN_Settings_Extra_Fields extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 4.0.0
* @since 4.0.0
*/
function __construct() {
$this->id = 'extra_fields';
$this->desc = __( 'Extra Fields', 'ean-for-woocommerce' );
parent::__construct();
}
/**
* get_settings.
*
* @version 4.7.6
* @since 4.0.0
*
* @todo (dev) `alg_wc_ean_extra_fields_num_total`: JS?
* @todo (dev) add "Meta key"?
* @todo (desc) better section desc?
* @todo (desc) better `pro_msg`?
*/
function get_settings() {
$settings = array(
array(
'title' => __( 'Extra Fields Options', 'ean-for-woocommerce' ),
'desc' => $this->pro_msg( 'use this section' ) .
__( 'This section allows you to add multiple extra fields per product, e.g., EAN and MPN simultaneously.', 'ean-for-woocommerce' ) . '<br>' .
__( 'Please note that extra fields have less features compared to the main field.', 'ean-for-woocommerce' ) . ' ' .
sprintf( __( 'Currently supported features are: %s.', 'ean-for-woocommerce' ), implode( ', ', array(
__( 'Title', 'ean-for-woocommerce' ),
__( 'Meta key', 'ean-for-woocommerce' ),
__( 'Admin product search', 'ean-for-woocommerce' ),
__( 'Single product page display (including variations)', 'ean-for-woocommerce' ),
__( 'Search (frontend)', 'ean-for-woocommerce' ),
__( 'Product structured data', 'ean-for-woocommerce' ),
) ) ),
'type' => 'title',
'id' => 'alg_wc_ean_extra_fields_options',
),
array(
'title' => __( 'Total extra fields', 'ean-for-woocommerce' ),
'type' => 'number',
'id' => 'alg_wc_ean_extra_fields_num_total',
'default' => 0,
'custom_attributes' => array( 'min' => 0 ),
),
);
for ( $i = 1; $i <= get_option( 'alg_wc_ean_extra_fields_num_total', 0 ); $i++ ) {
$settings = array_merge( $settings, array(
array(
'title' => sprintf( __( 'Extra field #%d', 'ean-for-woocommerce' ), $i ),
'type' => 'text',
'id' => "alg_wc_ean_extra_field_name[{$i}]",
'default' => sprintf( __( 'Extra field #%d', 'ean-for-woocommerce' ), $i ),
'custom_attributes' => array( 'required' => 'required' ),
),
) );
}
$settings = array_merge( $settings, array(
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_extra_fields_options',
),
) );
return $settings;
}
}
endif;
return new Alg_WC_EAN_Settings_Extra_Fields();

View File

@@ -0,0 +1,568 @@
<?php
/**
* EAN for WooCommerce - General Section Settings
*
* @version 4.8.1
* @since 1.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_General' ) ) :
class Alg_WC_EAN_Settings_General extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 1.0.0
* @since 1.0.0
*/
function __construct() {
$this->id = '';
$this->desc = __( 'General', 'ean-for-woocommerce' );
parent::__construct();
}
/**
* get_types_desc.
*
* @version 4.7.0
* @since 3.3.0
*
* @see https://en.wikipedia.org/wiki/Global_Trade_Item_Number
* @see https://en.wikipedia.org/wiki/EAN-8
* @see https://en.wikipedia.org/wiki/Universal_Product_Code
* @see https://en.wikipedia.org/wiki/International_Article_Number
* @see https://en.wikipedia.org/wiki/International_Standard_Book_Number
* @see https://en.wikipedia.org/wiki/International_Article_Number#jan
* @see https://www.barcode.graphics/gtin-14-encoding/
*/
function get_types_desc() {
$types = array(
'EAN-8' => array(
'desc' => __( 'Less commonly used EAN standard. An EAN-8 number includes a 2- or 3-digit GS1 prefix, 5- or 4-digit item reference element (depending on the length of the GS1 prefix), and a checksum digit.', 'ean-for-woocommerce' ),
'length' => 8,
),
'UPC-A' => array(
'desc' => __( 'The UPC-A barcode is the most common type in the United States. UPC (technically refers to UPC-A) consists of 12 digits. It begins with a single digit number system character, which designates how the code should be classified: as a regular product, a weighted item, pharmaceuticals, coupons, etc. After that is a five digit manufacturer\'s number, followed by a five digit product number, and finally a checksum digit.', 'ean-for-woocommerce' ),
'length' => 12,
),
'EAN-13' => array(
'desc' => __( 'This is the most commonly used EAN standard. An EAN-13 number includes a 3-digit GS1 prefix, 9-digit manufacturer and product code, and a checksum digit.', 'ean-for-woocommerce' ),
'length' => 13,
),
'ISBN-13' => array(
'desc' => __( 'The International Standard Book Number (ISBN) is a numeric commercial book identifier. It\'s a subset of EAN-13 - with <code>978</code> or <code>979</code> prefix.', 'ean-for-woocommerce' ),
'length' => 13,
),
'JAN' => array(
'desc' => __( 'Japanese Article Number (JAN) is a subset of EAN-13 - with <code>45</code> or <code>49</code> prefix.', 'ean-for-woocommerce' ),
'length' => 13,
),
'EAN14' => array(
'desc' => __( 'EAN-14 is a 14 digit number used to identify trade items at various packaging levels. The first digit denotes the level of packaging.', 'ean-for-woocommerce' ),
'length' => 14,
),
__( 'Custom', 'ean-for-woocommerce' ) => array(
'desc' => __( 'Custom can represent all 128 ASCII code characters (numbers, upper case/lower case letters, symbols and control codes).', 'ean-for-woocommerce' ),
'length' => __( 'Any', 'ean-for-woocommerce' ),
),
);
$result = '';
$result .= '<table class="widefat striped">' .
'<tr>' .
'<td><strong>' . __( 'Type', 'ean-for-woocommerce' ) . '</td>' .
'<td><strong>' . __( 'Length', 'ean-for-woocommerce' ) . '</td>' .
'<td><strong>' . __( 'Description', 'ean-for-woocommerce' ) . '</td>' .
'</tr>';
foreach ( $types as $title => $data ) {
$result .= '<tr>' .
"<td><pre><strong>{$title}</strong></pre></td>" .
"<td><code>{$data['length']}</code></td>" .
"<td>{$data['desc']}</td>" .
'</tr>';
}
$result .= '</table>';
return '<details style="cursor:pointer;"><summary>' . __( 'Type details', 'ean-for-woocommerce' ) . '</summary>' . $result . '</details>';
}
/**
* get_settings.
*
* @version 4.8.1
* @since 1.0.0
*
* @see https://www.keyence.com/ss/products/auto_id/barcode_lecture/basic/barcode-types/
*
* @todo (desc) `alg_wc_ean_backend_add_generate_button`: better desc?
* @todo (dev) `alg_wc_ean_order_items_table_templates`: translate?
* @todo (dev) deprecate placeholders
* @todo (dev) `alg_wc_ean_type`: rename `C128` to `CUSTOM`
* @todo (desc) `alg_wc_ean_order_items_meta_rest`: "... tries order item meta, then uses product as a fallback..."
* @todo (desc) add subsections, e.g., "General", "Display", etc., or "Products", "Orders", etc.?
* @todo (desc) "REST API" as a separate *section*?
* @todo (desc) remove "This will" everywhere
* @todo (dev) `alg_wc_ean_order_items_meta_admin`: default to `yes` || merge with `alg_wc_ean_order_items_meta`
* @todo (dev) `alg_wc_ean_order_items_meta`: default to `yes`
* @todo (desc) `alg_wc_ean_order_items_meta_admin`: better desc
* @todo (desc) `alg_wc_ean_order_items_meta`: better desc
* @todo (dev) `$single_product_page_positions`: add more options, and maybe add `custom` hook option?
* @todo (desc) `alg_wc_ean_frontend_positions_priorities`: better desc, e.g., add "known priorities"
* @todo (desc) `alg_wc_ean_frontend_search_ajax_flatsome`: add link to the theme?
* @todo (desc) Type: add more info (and maybe links) about all types
* @todo (desc) add shortcode examples
* @todo (desc) Type: rename to "Standard"?
* @todo (desc) Shop pages: better title/desc?
* @todo (desc) Cart: better desc?
* @todo (desc) `$wcdn_settings`: better desc?
* @todo (dev) `alg_wc_ean_backend_position`: add more positions?
* @todo (desc) `alg_wc_ean_backend_position`: better names, e.g., "Inventory: SKU" to "Inventory: After SKU", etc.
* @todo (dev) `alg_wc_ean_backend_search_ajax`: remove (i.e., always `yes`)?
*/
function get_settings() {
$single_product_page_positions = array(
'woocommerce_product_meta_start' => __( 'Product meta start', 'ean-for-woocommerce' ),
'woocommerce_product_meta_end' => __( 'Product meta end', 'ean-for-woocommerce' ),
'woocommerce_before_single_product' => __( 'Before single product', 'ean-for-woocommerce' ),
'woocommerce_before_single_product_summary' => __( 'Before single product summary', 'ean-for-woocommerce' ),
'woocommerce_single_product_summary' => __( 'Single product summary', 'ean-for-woocommerce' ),
'woocommerce_after_single_product_summary' => __( 'After single product summary', 'ean-for-woocommerce' ),
'woocommerce_after_single_product' => __( 'After single product', 'ean-for-woocommerce' ),
'woocommerce_product_additional_information' => __( 'Product additional information tab', 'ean-for-woocommerce' ),
);
$settings = array(
array(
'title' => __( 'EAN Options', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_plugin_options',
),
array(
'title' => __( 'EAN', 'ean-for-woocommerce' ),
'desc' => '<strong>' . __( 'Enable plugin', 'ean-for-woocommerce' ) . '</strong>',
'id' => 'alg_wc_ean_plugin_enabled',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Type', 'ean-for-woocommerce' ),
'desc' => $this->get_types_desc(),
'desc_tip' => sprintf( __( 'The "Type" will be used for: %s', 'ean-for-woocommerce' ),
'<br><br>' . implode( ',<br><br>', array(
'* ' . __( 'EAN validation (on the admin product edit pages, and in the admin products column)', 'ean-for-woocommerce' ),
'* ' . __( 'EAN input pattern (on the admin product edit pages)', 'ean-for-woocommerce' ),
'* ' . __( 'product structured data (e.g., for Google Search Console)', 'ean-for-woocommerce' ),
'* ' . __( 'outputting 1D barcodes', 'ean-for-woocommerce' ),
) ) . '.'
),
'id' => 'alg_wc_ean_type',
'default' => 'EAN13',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'AUTO' => __( 'Automatic', 'ean-for-woocommerce' ) . ' (' . implode( ', ', array( 'EAN-13', 'UPC-A', 'EAN-8', 'ISBN-13', 'JAN', 'EAN-14' ) ) . ')',
'EAN8' => 'EAN-8',
'UPCA' => 'UPC-A',
'EAN13' => 'EAN-13',
'ISBN13' => 'ISBN-13',
'JAN' => 'JAN',
'EAN14' => 'EAN-14',
'C128' => __( 'Custom', 'ean-for-woocommerce' ), // mislabeled, should be `CUSTOM`
),
),
array(
'title' => __( 'Title', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This title will be used for the EAN input fields on admin product edit pages, in admin products list column, etc.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_title',
'default' => __( 'EAN', 'ean-for-woocommerce' ),
'type' => 'text',
),
array(
'title' => __( 'Admin product edit page', 'ean-for-woocommerce' ),
'desc' => __( 'Position', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Set to which product data tab EAN field should be added.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_backend_position',
'default' => 'woocommerce_product_options_sku',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'woocommerce_product_options_general_product_data' => __( 'General', 'ean-for-woocommerce' ),
'woocommerce_product_options_inventory_product_data' => __( 'Inventory', 'ean-for-woocommerce' ),
'woocommerce_product_options_sku' => __( 'Inventory: SKU', 'ean-for-woocommerce' ),
'woocommerce_product_options_advanced' => __( 'Advanced', 'ean-for-woocommerce' ),
),
),
array(
'desc' => __( 'Position (variation product)', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_backend_position_variation',
'default' => 'woocommerce_variation_options_pricing',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'woocommerce_variation_options_pricing' => __( 'Variations: After pricing', 'ean-for-woocommerce' ),
'woocommerce_variation_options_dimensions' => __( 'Variations: After dimensions', 'ean-for-woocommerce' ),
'woocommerce_product_after_variable_attributes' => __( 'Variations: After all', 'ean-for-woocommerce' ),
),
),
array(
'desc' => __( 'Check if valid', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will check if product EAN is valid.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_backend_is_valid',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Check if unique', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will check if product EAN is unique in your shop.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_backend_is_unique',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Require', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will make the EAN field required on the admin product edit pages.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Add pattern', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will specify a maximum length and pattern (digits only) for the EAN input field to be checked against on the admin product edit pages.', 'ean-for-woocommerce' ) . ' ' .
__( 'Ignored if "Type" is set to "Custom".', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_add_pattern',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Add "Generate" button', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will add "Generate %s" button to the admin product edit pages.', 'ean-for-woocommerce' ),
get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ) ),
'id' => 'alg_wc_ean_backend_add_generate_button',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Admin product search', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will enable searching by EAN in admin area.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_backend_search',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'AJAX search', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will enable searching by EAN in AJAX.', 'ean-for-woocommerce' ) . ' ' .
__( 'E.g., when searching for a product when creating new order in admin area.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_backend_search_ajax',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Admin products list column', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'This will add "%s" column to %s.', 'ean-for-woocommerce' ),
get_option( 'alg_wc_ean_title', __( 'EAN', 'ean-for-woocommerce' ) ),
'<a href ="' . admin_url( 'edit.php?post_type=product' ) . '">' . __( 'admin products list', 'ean-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_ean_backend_column',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Validate', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Validate EAN in column.', 'ean-for-woocommerce' ) . ' ' . __( 'Invalid EANs will be marked red.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_backend_column_validate',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Admin product duplicate', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will copy EAN on admin "Duplicate" product action.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_duplicate_product',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Single product page', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will show EAN on single product page on frontend.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_frontend',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'desc' => __( 'Template', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Available placeholder: %s.', 'ean-for-woocommerce' ), '%ean%' ) . '<br><br>' .
__( 'You can also use shortcodes here.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_template',
'default' => alg_wc_ean()->core->get_default_template(),
'type' => 'textarea',
),
array(
'desc' => __( 'Positions', 'ean-for-woocommerce' ),
'desc_tip' => __( 'You can select multiple positions at once.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_frontend_positions',
'default' => array( 'woocommerce_product_meta_start' ),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => $single_product_page_positions,
),
);
foreach ( get_option( 'alg_wc_ean_frontend_positions', array( 'woocommerce_product_meta_start' ) ) as $position ) {
$position_title = ( isset( $single_product_page_positions[ $position ] ) ? $single_product_page_positions[ $position ] : $position );
$settings = array_merge( $settings, array(
array(
'desc' => sprintf( __( 'Position priority: "%s"', 'ean-for-woocommerce' ), $position_title ),
'desc_tip' => __( 'Fine-tune the position.', 'ean-for-woocommerce' ),
'id' => "alg_wc_ean_frontend_positions_priorities[{$position}]",
'default' => 10,
'type' => 'number',
),
) );
}
$settings = array_merge( $settings, array(
array(
'desc' => __( 'Variable products: Position in variation', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_frontend_variation_position',
'default' => 'product_meta',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'product_meta' => __( 'Product meta', 'ean-for-woocommerce' ),
'variation_description' => __( 'Description', 'ean-for-woocommerce' ),
),
),
array(
'title' => __( 'Shop pages', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will show EAN on shop (e.g., category) pages on frontend.', 'ean-for-woocommerce' ) . ' ' . $this->variable_products_note(),
'id' => 'alg_wc_ean_frontend_loop',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Template', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Available placeholder: %s.', 'ean-for-woocommerce' ), '%ean%' ) . '<br><br>' .
__( 'You can also use shortcodes here.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_template_loop',
'default' => alg_wc_ean()->core->get_default_template(),
'type' => 'textarea',
),
array(
'title' => __( 'Cart', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will show EAN on cart page on frontend.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_frontend_cart',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Search', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will enable searching by EAN on frontend.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_frontend_search',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( '"Flatsome" theme', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will enable searching by EAN in "Flatsome" theme\'s "LIVE SEARCH".', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_frontend_search_ajax_flatsome',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Product structured data', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_frontend_product_structured_data',
'desc_tip' => __( 'This will add EAN to the product structured data, e.g., for Google Search Console.', 'ean-for-woocommerce' ),
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => sprintf( __( '"%s" plugin', 'ean-for-woocommerce' ), __( 'Rank Math SEO', 'ean-for-woocommerce' ) ),
'desc_tip' => sprintf( __( 'This will add EAN to the product structured data generated by the %s plugin.', 'ean-for-woocommerce' ),
'<a href ="https://wordpress.org/plugins/seo-by-rank-math/" target="_blank">' . __( 'Rank Math SEO', 'ean-for-woocommerce' ) . '</a>' ),
'id' => 'alg_wc_ean_frontend_product_structured_data_rank_math_seo',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Automatic key', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'If enabled, will use the key based on EAN type, i.e., %s for EAN-8, %s for UPC-A, %s for EAN-13, ISBN-13 and JAN, %s for EAN-14, and %s for all other types.', 'ean-for-woocommerce' ),
'<code>gtin8</code>', '<code>gtin12</code>', '<code>gtin13</code>', '<code>gtin14</code>', '<code>gtin</code>' ),
'id' => 'alg_wc_ean_frontend_product_structured_data_key_auto',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'desc' => __( 'Custom key', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Ignored, unless the "Automatic key" option above is disabled.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_frontend_product_structured_data_key',
'default' => 'gtin',
'type' => 'text',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_plugin_options',
),
array(
'title' => __( 'Orders & Emails', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_orders_options',
),
array(
'title' => __( 'Orders', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Add EAN to new order items meta.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_order_items_meta',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Admin order', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Add EAN to new order items meta for orders created by admin.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_order_items_meta_admin',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Order items table', 'ean-for-woocommerce' ),
'desc' => __( 'Pages', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will show EAN in order items table on <strong>pages</strong>.', 'ean-for-woocommerce' ) . ' ' .
__( 'E.g.: "thank you" (i.e., "order received") page, "view order" page (in "my account").', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_order_items_table',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Emails', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will show EAN in order items table in <strong>emails</strong>.', 'ean-for-woocommerce' ) . ' ' .
__( 'You can limit it to the specific emails in the "Emails list" option below.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_order_items_table_emails',
'default' => get_option( 'alg_wc_ean_order_items_table', 'no' ), // for the backward compatibility
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'desc' => __( 'Emails list', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Leave empty to add to all emails.', 'ean-for-woocommerce' ) . ' ' .
__( 'Ignored unless the "Emails" option above is enabled.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_order_items_table_emails_list',
'default' => array(),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => $this->get_wc_emails(),
),
array(
'desc' => __( 'Template (HTML)', 'ean-for-woocommerce' ) . '<br>' .
sprintf( __( 'Available placeholder(s): %s', 'ean-for-woocommerce' ), '<code>%ean%</code>' ),
'id' => 'alg_wc_ean_order_items_table_templates[html]',
'default' => '<ul class="wc-item-meta"><li><span class="sku_wrapper ean_wrapper">EAN: <span class="ean">%ean%</span></span></li></ul>',
'type' => 'textarea',
'css' => 'height:100px;'
),
array(
'desc' => __( 'Template (Plain text (emails only))', 'ean-for-woocommerce' ) . '<br>' .
sprintf( __( 'Available placeholder(s): %s', 'ean-for-woocommerce' ), '<code>%ean%</code>, <code>%new_line%</code>' ),
'id' => 'alg_wc_ean_order_items_table_templates[plain_text]',
'default' => '%new_line%- EAN: %ean%',
'type' => 'textarea',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_orders_options',
),
array(
'title' => __( 'REST API', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_rest_api_options',
),
array(
'title' => __( 'Products', 'ean-for-woocommerce' ),
'desc' => __( 'Add EAN to each product object in REST API responses', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'E.g.: %s', 'ean-for-woocommerce' ), '<code>https://example.com/wp-json/wc/v3/products/123</code>' ),
'id' => 'alg_wc_ean_product_rest',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Search by EAN', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'E.g.: %s', 'ean-for-woocommerce' ), '<code>https://example.com/wp-json/wc/v3/products?ean=7980441417892</code>' ) .
'<br>* ' . sprintf( __( 'Alternatively, you can enable the "Search > This will enable searching by EAN on frontend" option, and then search using the standard %s parameter:', 'ean-for-woocommerce' ),
'<code>search</code>' ) .
'<br>' . sprintf( __( 'E.g.: %s', 'ean-for-woocommerce' ), '<code>https://example.com/wp-json/wc/v3/products?search=7980441417892</code>' ),
'id' => 'alg_wc_ean_product_search_rest',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Orders', 'ean-for-woocommerce' ),
'desc' => __( 'Add EAN to each order object in REST API responses', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'E.g.: %s', 'ean-for-woocommerce' ), '<code>https://example.com/wp-json/wc/v3/orders/465</code>' ),
'id' => 'alg_wc_ean_order_items_meta_rest',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Search by EAN', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'E.g.: %s', 'ean-for-woocommerce' ), '<code>https://example.com/wp-json/wc/v3/orders?ean=7980441417892</code>' ) .
'<br>* ' . __( 'Please note that the "Orders > Add EAN to new order items meta" option must be enabled.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_order_items_meta_search_rest',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_rest_api_options',
),
array(
'title' => __( 'Notes', 'ean-for-woocommerce' ),
'desc' => implode( '<br>', array(
'<span class="dashicons dashicons-info"></span> ' . sprintf( __( 'You can also output EAN with %s shortcode.', 'ean-for-woocommerce' ),
'<code>[alg_wc_ean]</code>' ),
'<span class="dashicons dashicons-info"></span> ' . sprintf( __( 'EAN is stored in product meta with %s key. You may need this for some third-party plugins, e.g., for product import.', 'ean-for-woocommerce' ),
'<code>' . alg_wc_ean()->core->ean_key . '</code>' ),
) ),
'type' => 'title',
'id' => 'alg_wc_ean_notes',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_notes',
),
) );
return $settings;
}
}
endif;
return new Alg_WC_EAN_Settings_General();

View File

@@ -0,0 +1,159 @@
<?php
/**
* EAN for WooCommerce - Print Products Section Settings
*
* @version 4.3.0
* @since 4.3.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Print_Products' ) ) :
class Alg_WC_EAN_Settings_Print_Products extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 4.3.0
* @since 4.3.0
*/
function __construct() {
$this->id = 'print_products';
$this->desc = __( 'Print Products', 'ean-for-woocommerce' );
parent::__construct();
add_action( 'woocommerce_settings_' . 'alg_wc_ean', array( $this, 'before_table' ), 9 );
add_action( 'woocommerce_settings_' . 'alg_wc_ean', array( $this, 'after_table' ), 11 );
}
/**
* print_button.
*
* @version 4.3.0
* @since 4.3.0
*
* @see https://github.com/woocommerce/woocommerce/blob/6.7.0/plugins/woocommerce/includes/admin/views/html-admin-settings.php#L40
*/
function print_button() {
?>
<p class="submit">
<button name="save" class="button-primary woocommerce-save-button" type="submit" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>"><?php esc_html_e( 'Print', 'ean-for-woocommerce' ); ?></button>
</p>
<?php
}
/**
* before_table.
*
* @version 4.3.0
* @since 4.3.0
*/
function before_table() {
global $current_section;
if ( 'print_products' === $current_section ) {
echo '<h2>' . esc_html__( 'Print Products Tool', 'ean-for-woocommerce' ) . '</h2>';
$this->print_button();
}
}
/**
* after_table.
*
* @version 4.3.0
* @since 4.3.0
*/
function after_table() {
global $current_section;
if ( 'print_products' === $current_section ) {
$this->print_button();
$GLOBALS['hide_save_button'] = true;
}
}
/**
* style.
*
* @version 4.3.0
* @since 4.3.0
*/
function style() {
?>
<style>
.form-table,
.form-table th,
.form-table td {
padding: 5px;
width: auto;
border: 1px solid #ddd;
}
.woocommerce table.form-table input[type=number] {
width: 4em;
}
</style>
<?php
}
/**
* get_settings.
*
* @version 4.3.0
* @since 4.3.0
*
* @todo (dev) pagination
* @todo (dev) `set_transient( 'alg_wc_ean_print_products_list', $products, HOUR_IN_SECONDS )`, `get_transient( 'alg_wc_ean_print_products_list' )`?
*/
function get_settings() {
$settings = array();
add_action( 'admin_footer', array( $this, 'style' ), PHP_INT_MAX );
$products = wc_get_products( array(
'limit' => -1,
'return' => 'ids',
'orderby' => 'title',
'order' => 'ASC',
'type' => array_merge( array_keys( wc_get_product_types() ), array( 'variation' ) ),
) );
$settings = array_merge( $settings, array(
array(
'type' => 'title',
'id' => 'alg_wc_ean_print_products_list_options',
),
) );
foreach ( $products as $product_id ) {
$settings = array_merge( $settings, array(
array(
'title' => sprintf( '%s (%s)',
get_the_title( $product_id ), ( '' !== ( $sku = get_post_meta( $product_id, '_sku', true ) ) ? $sku : '#' . $product_id ) ),
'type' => 'number',
'id' => "alg_wc_ean_print_products_list[{$product_id}]",
'default' => '',
'custom_attributes' => array( 'min' => 0 ),
),
) );
}
$settings = array_merge( $settings, array(
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_print_products_list_options',
),
) );
return $settings;
}
}
endif;
return new Alg_WC_EAN_Settings_Print_Products();

View File

@@ -0,0 +1,510 @@
<?php
/**
* EAN for WooCommerce - Print Section Settings
*
* @version 4.7.4
* @since 2.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Print' ) ) :
class Alg_WC_EAN_Settings_Print extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 2.0.0
* @since 2.0.0
*/
function __construct() {
$this->id = 'print';
$this->desc = __( 'Print', 'ean-for-woocommerce' );
parent::__construct();
}
/**
* get_settings.
*
* @version 4.7.4
* @since 2.0.0
*
* @see https://www.avery.com/templates/6879 (default margins etc.)
*
* @todo (feature) predefined templates, e.g., with `<table>`
* @todo (feature) Cell border: add customization options
* @todo (desc) "Deprecated placeholders" desc tip: remove?
* @todo (feature) `wpautop()`?
* @todo (desc) `children`: better desc?
* @todo (desc) better section desc?
* @todo (desc) Page format: better desc?
*/
function get_settings() {
$options = get_option( 'alg_wc_ean_print_barcodes_to_pdf_settings', array() );
$unit = ( isset( $options['unit'] ) ? $options['unit'] : 'in' );
$units = array(
'mm' => __( 'millimeters', 'ean-for-woocommerce' ),
'cm' => __( 'centimeters', 'ean-for-woocommerce' ),
'in' => __( 'inches', 'ean-for-woocommerce' ),
'pt' => __( 'points', 'ean-for-woocommerce' ),
);
$unit_title = $units[ $unit ];
$point_desc = __( 'A point equals 1/72 of inch, that is to say about 0.35 mm (an inch being 2.54 cm). This is a very common unit in typography; font sizes are expressed in that unit.', 'ean-for-woocommerce' );
$pdf_page_formats = require( 'alg-wc-ean-pdf-page-formats.php' );
foreach ( $pdf_page_formats as $format_id => $format_dim ) {
// Converting from points to `$unit`
switch ( $unit ) {
case 'mm':
$format_dim_w = round( $format_dim[0] / 2.835 );
$format_dim_h = round( $format_dim[1] / 2.835 );
break;
case 'cm':
$format_dim_w = round( $format_dim[0] / 28.35, 1 );
$format_dim_h = round( $format_dim[1] / 28.35, 1 );
break;
default: // 'in'
$format_dim_w = round( $format_dim[0] / 72, 1 );
$format_dim_h = round( $format_dim[1] / 72, 1 );
}
$pdf_page_formats[ $format_id ] = "{$format_id} ({$format_dim_w} x {$format_dim_h} {$unit_title})";
}
$settings = array(
array(
'title' => __( 'Print Barcodes (PDF)', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_options',
),
array(
'title' => __( 'Print barcodes (PDF)', 'ean-for-woocommerce' ),
'desc' => '<strong>' . __( 'Enable section', 'ean-for-woocommerce' ) . '</strong>',
'desc_tip' => sprintf( __( 'This will add "Print barcodes" to the "Bulk actions" in %s.', 'ean-for-woocommerce' ),
'<a href="' . admin_url( 'edit.php?post_type=product' ) . '">' . __( 'admin products list', 'ean-for-woocommerce' ) . '</a>' ) . $this->pro_msg(),
'id' => 'alg_wc_ean_print_barcodes_to_pdf',
'default' => 'no',
'type' => 'checkbox',
'custom_attributes' => apply_filters( 'alg_wc_ean_settings', array( 'disabled' => 'disabled' ) ),
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_options',
),
array(
'title' => __( 'General Options', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_general_options',
),
array(
'title' => __( 'Page orientation', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[page_orientation]',
'default' => 'P',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'P' => __( 'Portrait', 'ean-for-woocommerce' ),
'L' => __( 'Landscape', 'ean-for-woocommerce' ),
),
),
array(
'title' => __( 'Unit', 'ean-for-woocommerce' ),
'desc_tip' => __( 'User measure unit.', 'ean-for-woocommerce' ) . '<br><br>' .
sprintf( __( 'Used in %s options.', 'ean-for-woocommerce' ), '"' . implode( '", "', array(
__( 'Page format: Custom: Width', 'ean-for-woocommerce' ),
__( 'Page format: Custom: Height', 'ean-for-woocommerce' ),
__( 'Cell width', 'ean-for-woocommerce' ),
__( 'Cell height', 'ean-for-woocommerce' ),
__( 'Top margin', 'ean-for-woocommerce' ),
__( 'Left margin', 'ean-for-woocommerce' ),
__( 'Right margin', 'ean-for-woocommerce' ),
__( 'Page break margin', 'ean-for-woocommerce' ),
) ) . '"' ) . '<br><br>' .
'* ' . $point_desc,
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[unit]',
'default' => 'in',
'type' => 'select',
'class' => 'chosen_select',
'options' => $units,
),
array(
'title' => __( 'Page format', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[page_format]',
'default' => 'LETTER',
'type' => 'select',
'class' => 'chosen_select',
'options' => array_merge( array( 'custom' => __( 'Custom', 'ean-for-woocommerce' ) ), $pdf_page_formats ),
),
array(
'desc' => __( 'Page format: Custom: Width', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ) . '<br><br>' .
sprintf( __( 'Ignored unless "%s" option is set to "%s".', 'ean-for-woocommerce' ),
__( 'Page format', 'ean-for-woocommerce' ), __( 'Custom', 'ean-for-woocommerce' ) ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[page_format_custom_width]',
'default' => 0,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Page format: Custom: Height', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ) . '<br><br>' .
sprintf( __( 'Ignored unless "%s" option is set to "%s".', 'ean-for-woocommerce' ),
__( 'Page format', 'ean-for-woocommerce' ), __( 'Custom', 'ean-for-woocommerce' ) ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[page_format_custom_height]',
'default' => 0,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'title' => __( 'Max barcodes per page', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[per_page]',
'default' => 12,
'type' => 'number',
'custom_attributes' => array( 'min' => 1 ),
),
array(
'title' => __( 'Columns', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[columns]',
'default' => 2,
'type' => 'number',
'custom_attributes' => array( 'min' => 1 ),
),
array(
'title' => __( 'Cell', 'ean-for-woocommerce' ),
'desc' => __( 'Cell width', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[cell_width]',
'default' => 4,
'type' => 'number',
'custom_attributes' => array( 'min' => 0.000001, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Cell height', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[cell_height]',
'default' => 1.5,
'type' => 'number',
'custom_attributes' => array( 'min' => 0.000001, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Cell border', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[cell_border]',
'default' => 0,
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
0 => __( 'No', 'ean-for-woocommerce' ),
1 => __( 'Yes', 'ean-for-woocommerce' ),
),
),
array(
'desc' => __( 'Cell top margin', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[cell_margin_top]',
'default' => 0,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Cell left margin', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[cell_margin_left]',
'default' => 0,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Cell right margin', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[cell_margin_right]',
'default' => 0,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Cell bottom margin', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[cell_margin_bottom]',
'default' => 0,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Cell content alignment', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[cell_align]',
'default' => '',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'' => __( 'Default', 'ean-for-woocommerce' ),
'L' => __( 'Left', 'ean-for-woocommerce' ),
'C' => __( 'Center', 'ean-for-woocommerce' ),
'R' => __( 'Right', 'ean-for-woocommerce' ),
),
),
array(
'title' => __( 'Page margins', 'ean-for-woocommerce' ),
'desc' => __( 'Top margin', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[margin_top]',
'default' => 1.13,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Left margin', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[margin_left]',
'default' => 0.46,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Right margin', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[margin_right]',
'default' => 0.31,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'desc' => __( 'Page break (i.e., bottom) margin', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'In %s.', 'ean-for-woocommerce' ), $unit_title ) . '<br><br>' .
__( 'Distance from the bottom of the page that defines the automatic page breaking triggering limit.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[page_break_margin]',
'default' => 0.79,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'step' => 0.000001 ),
),
array(
'title' => __( 'Font', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'If you are having issues displaying your language specific letters, select "%s" font.', 'ean-for-woocommerce' ),
'DejaVu Sans (Unicode)' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[font_family]',
'default' => 'dejavusans',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'dejavusans' => 'DejaVu Sans (Unicode)',
'times' => 'Times New Roman',
'helvetica' => 'Helvetica',
'courier' => 'Courier',
),
),
array(
'title' => __( 'Font size', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[font_size]',
'default' => 11,
'type' => 'number',
'custom_attributes' => array( 'min' => 1 ),
),
array(
'title' => __( 'Template', 'ean-for-woocommerce' ),
'desc' => sprintf( '<details><summary style="%s">%s</summary>%s</details>',
'cursor: pointer; color: #2271b1;',
__( 'Available shortcodes', 'ean-for-woocommerce' ),
'<ul><li><code>' . implode( '</code></li><li><code>', array(
'[alg_wc_ean]',
'[alg_wc_ean_barcode]',
'[alg_wc_ean_barcode_2d]',
'[alg_wc_ean_product_image]',
'[alg_wc_ean_product_name]',
'[alg_wc_ean_product_price]',
'[alg_wc_ean_product_sku]',
'[alg_wc_ean_product_attr]',
'[alg_wc_ean_product_id]',
'[alg_wc_ean_product_meta]',
'[alg_wc_ean_product_function]',
) ) . '</code></li></ul>' ),
'desc_tip' => apply_filters( 'alg_wc_ean_print_barcodes_to_pdf_template_settings_desc', '' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[template]',
'default' => '[alg_wc_ean_barcode]<br>[alg_wc_ean]',
'type' => 'textarea',
'css' => 'width:100%;height:200px;',
),
array(
'title' => __( 'Style', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Defines style information (CSS) for the labels.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[style]',
'default' => '',
'type' => 'textarea',
'css' => 'width:100%;height:100px;',
),
array(
'title' => __( 'Variations', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[children]',
'default' => 'no',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'no' => __( 'Do not include', 'ean-for-woocommerce' ),
'yes' => __( 'Add', 'ean-for-woocommerce' ),
'replace' => __( 'Replace', 'ean-for-woocommerce' ),
),
),
array(
'title' => __( 'Use stock quantity', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Print separate label for each product inventory item.', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[use_qty]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_general_options',
),
);
$settings = apply_filters( 'alg_wc_ean_print_barcodes_to_pdf_general_settings', $settings, $options );
$settings = array_merge( $settings, array(
array(
'title' => __( 'Admin Options', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_admin_options',
),
array(
'title' => __( 'Print buttons', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings_print_buttons',
'default' => array( 'bulk_actions' ),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => array(
'bulk_actions' => __( 'Products > Bulk actions', 'ean-for-woocommerce' ),
'single_product' => __( 'Single product', 'ean-for-woocommerce' ),
'single_order' => __( 'Single order', 'ean-for-woocommerce' ),
),
),
array(
'desc' => sprintf( __( 'Print buttons style, e.g.: %s', 'ean-for-woocommerce' ), '<code>font-size: 40px; width: 40px; height: 40px;</code>' ),
'desc_tip' => sprintf( __( 'Applied to the "%s" and "%s" print buttons.', 'ean-for-woocommerce' ),
__( 'Single product', 'ean-for-woocommerce' ), __( 'Single order', 'ean-for-woocommerce' ) ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings_print_buttons_style',
'default' => '',
'type' => 'text',
),
array(
'desc' => __( 'Variations print buttons', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Applied to the "%s" print buttons.', 'ean-for-woocommerce' ),
__( 'Single product', 'ean-for-woocommerce' ) ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings_buttons_variations',
'default' => array( 'variations_tab' ),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => array(
'variations_tab' => __( 'Variations tab', 'ean-for-woocommerce' ),
'meta_box' => __( 'Meta box', 'ean-for-woocommerce' ),
),
),
array(
'desc' => __( 'Quantity input', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Adds quantity input field for the print buttons.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings_print_qty',
'default' => array(),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => array(
'bulk_actions' => __( 'Products > Bulk actions', 'ean-for-woocommerce' ),
'bulk_actions_each_product' => __( 'Products > Bulk actions > Each product', 'ean-for-woocommerce' ),
),
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_admin_options',
),
array(
'title' => __( 'Advanced Print Options', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_advanced_options',
),
array(
'title' => __( 'Skip products without EAN', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Skip products without EAN when generating PDF.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings_skip_empty_ean',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Use Print.js', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => sprintf( __( 'Use %s library for printing PDFs.', 'ean-for-woocommerce' ),
'<a href="https://printjs.crabbly.com/" target="_blank">Print.js</a>' ),
'id' => 'alg_wc_ean_print_use_print_js',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Suppress errors', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ) . ' (' . __( 'recommended', 'ean-for-woocommerce' ) . ')',
'desc_tip' => __( 'Suppress PHP errors when generating PDF.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_settings[suppress_errors]',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_advanced_options',
),
array(
'title' => __( 'Print Tools', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_tools',
),
array(
'title' => __( 'Print', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Print', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Check the box and "Save changes" to run the tool.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_tool',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Product(s)', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_tool_data[products]',
'default' => array(),
'type' => 'multiselect',
'class' => 'wc-product-search',
'options' => array(),
'custom_attributes' => array(
'data-placeholder' => esc_attr__( 'Search for a product&hellip;', 'woocommerce' ),
'data-action' => 'woocommerce_json_search_products_and_variations',
'data-allow_clear' => true,
),
),
array(
'desc' => __( 'Quantity', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_barcodes_to_pdf_tool_data[qty]',
'default' => 1,
'type' => 'number',
'placeholder' => '1',
'custom_attributes' => array( 'min' => 1 ),
),
array(
'title' => __( 'Products List', 'ean-for-woocommerce' ),
'desc' => __( 'Enable', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This will add new "Print Products" section to "WooCommerce > Settings > EAN".', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_print_products_list_section',
'default' => 'no',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_print_barcodes_to_pdf_tools',
),
) );
return $settings;
}
}
endif;
return new Alg_WC_EAN_Settings_Print();

View File

@@ -0,0 +1,80 @@
<?php
/**
* EAN for WooCommerce - Section Settings
*
* @version 4.0.0
* @since 1.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Section' ) ) :
class Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 1.0.0
* @since 1.0.0
*/
function __construct() {
add_filter( 'woocommerce_get_sections_alg_wc_ean', array( $this, 'settings_section' ) );
add_filter( 'woocommerce_get_settings_alg_wc_ean_' . $this->id, array( $this, 'get_settings' ), PHP_INT_MAX );
}
/**
* settings_section.
*
* @version 1.0.0
* @since 1.0.0
*/
function settings_section( $sections ) {
$sections[ $this->id ] = $this->desc;
return $sections;
}
/**
* pro_msg.
*
* @version 4.0.0
* @since 2.0.0
*/
function pro_msg( $msg = 'enable this section' ) {
return apply_filters( 'alg_wc_ean_settings', '<p style="padding:15px;color:black;background-color:white;font-weight:bold;">' .
sprintf( 'You will need <a target="_blank" href="https://wpfactory.com/item/ean-for-woocommerce/">EAN for WooCommerce Pro</a> plugin version to %s.', $msg ) .
'</p>' );
}
/**
* variable_products_note.
*
* @version 2.4.0
* @since 2.0.0
*
* @todo (desc) better desc?
*/
function variable_products_note() {
return __( 'Please note that for the <strong>variable</strong> products, <strong>main</strong> product\'s EAN must be set.', 'ean-for-woocommerce' );
}
/**
* get_wc_emails.
*
* @version 3.1.0
* @since 3.1.0
*/
function get_wc_emails() {
$emails = array();
$wc_emails = WC_Emails::instance();
foreach ( $wc_emails->get_emails() as $email_id => $email ) {
$emails[ $email->id ] = $email->get_title();
}
return $emails;
}
}
endif;

View File

@@ -0,0 +1,489 @@
<?php
/**
* EAN for WooCommerce - Tools Section Settings
*
* @version 4.8.3
* @since 2.2.5
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings_Tools' ) ) :
class Alg_WC_EAN_Settings_Tools extends Alg_WC_EAN_Settings_Section {
/**
* Constructor.
*
* @version 2.2.5
* @since 2.2.5
*/
function __construct() {
$this->id = 'tools';
$this->desc = __( 'Tools', 'ean-for-woocommerce' );
parent::__construct();
}
/**
* get_product_actions_list.
*
* @version 4.4.2
* @since 2.9.0
*/
function get_product_actions_list() {
return array(
'' => __( 'Disabled', 'ean-for-woocommerce' ),
'generate' => __( 'Generate', 'ean-for-woocommerce' ),
'copy_sku' => __( 'Copy from product SKU', 'ean-for-woocommerce' ),
'copy_id' => __( 'Copy from product ID', 'ean-for-woocommerce' ),
'copy_meta' => __( 'Copy from product meta', 'ean-for-woocommerce' ),
'copy_attr' => __( 'Copy from product attribute', 'ean-for-woocommerce' ),
'assign_list' => __( 'Assign from the list', 'ean-for-woocommerce' ),
'copy_to_sku' => __( 'Copy to product SKU', 'ean-for-woocommerce' ),
'copy_to_meta' => __( 'Copy to product meta', 'ean-for-woocommerce' ),
'copy_to_attr' => __( 'Copy to product attribute', 'ean-for-woocommerce' ),
);
}
/**
* get_missing_product_cat_title.
*
* @version 3.0.0
* @since 3.0.0
*/
function get_missing_product_cat_title( $term_id ) {
return sprintf( __( 'Product category #%s', 'ean-for-woocommerce' ), $term_id );
}
/**
* get_terms.
*
* @version 3.0.0
* @since 3.0.0
*
* @todo (desc) add term ID?
*/
function get_terms( $taxonomy, $option ) {
$terms = get_option( $option, array() );
$terms = ( ! empty( $terms[ $taxonomy ] ) ? array_combine( $terms[ $taxonomy ], array_map( array( $this, "get_missing_{$taxonomy}_title" ), $terms[ $taxonomy ] ) ) : array() );
$_terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false ) );
$_terms = ( ! empty( $_terms ) && ! is_wp_error( $_terms ) ? array_combine( wp_list_pluck( $_terms, 'term_id' ), wp_list_pluck( $_terms, 'name' ) ) : array() );
return array_replace( $terms, $_terms );
}
/**
* get_product_attributes.
*
* @version 4.6.0
* @since 3.7.2
*/
function get_product_attributes( $none_title = false, $do_add_custom = false ) {
$options = array();
$options[''] = ( $none_title ? $none_title : esc_html__( 'Disable', 'ean-for-woocommerce' ) );
if ( $do_add_custom ) {
$options['alg_wc_ean_product_attribute_custom'] = '(' . esc_html__( 'Custom', 'ean-for-woocommerce' ) . ')';
}
$taxonomies = wc_get_attribute_taxonomies();
if ( ! empty( $taxonomies ) ) {
foreach ( $taxonomies as $tax ) {
$id = esc_attr( wc_attribute_taxonomy_name( $tax->attribute_name ) );
$label = esc_html( $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name );
$options[ $id ] = $label;
}
}
return $options;
}
/**
* get_settings.
*
* @version 4.8.3
* @since 2.2.5
*
* @todo (dev) Product Tools: Generate: Type: `EAN14`
* @todo (dev) `alg_wc_ean_product_bulk_actions_confirm`: better default value?
* @todo (dev) "Product tags" (similar to "Product categories")
* @todo (dev) add "Product categories" (and "Product tags") to all tools (now only in "Assign from the list")
* @todo (desc) add subsections, e.g.: "Automatic and Periodic Actions", "Bulk Actions"
* @todo (desc) Periodic action: rename?
* @todo (desc) `seed_prefix`
* @todo (desc) "Order Tools": add info about "General > Orders" options (i.e., "Add EAN to new order items meta", etc.)
* @todo (desc) better desc for all tools?
*/
function get_settings() {
$settings = array(
array(
'title' => __( 'Tools', 'ean-for-woocommerce' ),
'desc' => sprintf( __( 'Check the %s box and "Save changes" to run the tool. Please note that there is no undo for these tools.', 'ean-for-woocommerce' ),
'<span class="dashicons dashicons-admin-generic"></span>' ),
'type' => 'title',
'id' => 'alg_wc_ean_tools',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_tools',
),
array(
'title' => __( 'Product Tools', 'ean-for-woocommerce' ),
'desc' => sprintf( __( 'Please note that %s, %s and %s tools will <strong>not</strong> overwrite EANs for products with existing EANs.', 'ean-for-woocommerce' ),
'<strong>' . __( 'Generate', 'ean-for-woocommerce' ) . '</strong>',
'<strong>' . __( 'Copy', 'ean-for-woocommerce' ) . '</strong>',
'<strong>' . __( 'Assign', 'ean-for-woocommerce' ) . '</strong>' ) . ' ' .
sprintf( __( 'You can use the %s tool to clear the existing EANs before generating or copying.', 'ean-for-woocommerce' ),
'<strong>' . __( 'Delete', 'ean-for-woocommerce' ) . '</strong>' ),
'type' => 'title',
'id' => 'alg_wc_ean_tools_products',
),
array(
'title' => __( 'Generate', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Generate EAN for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[generate]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Type', 'ean-for-woocommerce' ),
'desc_tip' =>
'* ' . __( 'To generate ISBN-13, set this option to "EAN-13", and then set the "Country prefix" option to 978 or 979.', 'ean-for-woocommerce' ) . '<br><br>' .
'* ' . __( 'To generate JAN, set this option to "EAN-13", and then set the "Country prefix" option to a number in the 450-459 range or in the 490-499 range.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_generate[type]',
'default' => 'EAN13',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'EAN8' => 'EAN-8',
'UPCA' => 'UPC-A',
'EAN13' => 'EAN-13',
),
),
array(
'desc' => __( 'Country prefix (from)', 'ean-for-woocommerce' ) . ' ' .
sprintf( '<a target="_blank" title="%s" style="text-decoration:none;" href="%s">%s</a>',
__( 'List of GS1 country codes.', 'ean-for-woocommerce' ),
'https://en.wikipedia.org/wiki/List_of_GS1_country_codes',
'<span class="dashicons dashicons-external"></span>' ),
'id' => 'alg_wc_ean_tool_product_generate[prefix]',
'default' => 200,
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'max' => 999 ),
),
array(
'desc' => __( 'County prefix (to)', 'ean-for-woocommerce' ) . ' (' . __( 'optional', 'ean-for-woocommerce' ) . ')',
'desc_tip' => sprintf( __( 'If set, prefix will be generated randomly between "%s" and "%s" values.', 'ean-for-woocommerce' ),
__( 'Prefix from', 'ean-for-woocommerce' ), __( 'Prefix to', 'ean-for-woocommerce' ) ),
'id' => 'alg_wc_ean_tool_product_generate[prefix_to]',
'default' => '',
'type' => 'number',
'custom_attributes' => array( 'min' => 0, 'max' => 999 ),
),
array(
'desc' => __( 'County prefix length', 'ean-for-woocommerce' ),
'desc_tip' => __( 'For EAN-8 type only. County prefix length for other types will always be 3.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_generate[prefix_length]',
'default' => 3,
'type' => 'number',
'custom_attributes' => array( 'min' => 2, 'max' => 3 ),
),
array(
'desc' => __( 'Seed prefix', 'ean-for-woocommerce' ) . ' (' . __( 'optional', 'ean-for-woocommerce' ) . ')',
'desc_tip' => __( 'Or manufacturer code.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_generate[seed_prefix]',
'default' => '',
'type' => 'text',
'custom_attributes' => array( 'pattern' => '[0-9]+' ),
),
array(
'desc' => __( 'Seed', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Or product code.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_generate[seed_method]',
'default' => 'product_id',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'product_id' => __( 'Product ID', 'ean-for-woocommerce' ),
'counter' => __( 'Counter', 'ean-for-woocommerce' ),
),
),
array(
'desc' => __( 'Seed counter', 'ean-for-woocommerce' ) . ' (' . __( 'ignored unless "Seed" option is set to "Counter"', 'ean-for-woocommerce' ) . ')',
'id' => 'alg_wc_ean_tool_product_generate_seed_counter',
'default' => 0,
'type' => 'number',
'custom_attributes' => array( 'min' => 0 ),
),
array(
'desc' => __( 'Product attribute', 'ean-for-woocommerce' ) . ' (' . __( 'optional', 'ean-for-woocommerce' ) . ')',
'desc_tip' => __( 'If enabled, will copy the generated EAN to the selected product attribute as well.', 'ean-for-woocommerce' ) . ' (' . __( 'optional', 'ean-for-woocommerce' ) . ')',
'id' => 'alg_wc_ean_tool_product_generate[product_attribute]',
'default' => '',
'type' => 'select',
'class' => 'chosen_select',
'options' => $this->get_product_attributes(),
),
array(
'title' => __( 'Copy from product SKU', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Copy EAN from product SKU for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[copy_sku]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Copy from product ID', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Copy EAN from product ID for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[copy_id]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Copy from product meta', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Copy EAN from product meta for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[copy_meta]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => sprintf( __( 'Meta key, e.g., %s', 'ean-for-woocommerce' ), '<code>_gtin</code>' ),
'desc_tip' => __( 'Product meta key to copy from.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_copy_meta[key]',
'default' => '',
'type' => 'text',
),
array(
'desc' => __( 'Meta sub key', 'ean-for-woocommerce' ) . ' (' . __( 'optional', 'ean-for-woocommerce' ) . ')',
'desc_tip' => __( 'Optional sub key. This is used when meta was saved in an array.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_copy_meta[sub_key]',
'default' => '',
'type' => 'text',
),
array(
'title' => __( 'Copy from product attribute', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Copy EAN from product attribute for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[copy_attr]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Product attribute', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_copy_attr[product_attribute]',
'default' => '',
'type' => 'select',
'class' => 'chosen_select',
'options' => $this->get_product_attributes( __( 'Select attribute...', 'ean-for-woocommerce' ), true ),
),
array(
'desc' => __( 'Custom product attribute', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Ignored, unless the "Product attribute" option is set to "Custom".', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_copy_attr[product_attribute_custom]',
'default' => '',
'type' => 'text',
),
array(
'title' => __( 'Assign from the list', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Assign EAN from the list for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[assign_list]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Product categories', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Sets which product categories to include when assigning the EANs (i.e., all other categories will be skipped).', 'ean-for-woocommerce' ) . ' ' .
__( 'Leave blank to use all product categories.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_assign_list_settings[product_cat]',
'default' => array(),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => $this->get_terms( 'product_cat', 'alg_wc_ean_tool_product_assign_list_settings' ),
),
array(
'desc' => __( 'Reuse deleted', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Will add EANs from the deleted products to the "List" option.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_assign_list_settings[reuse_deleted]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'List', 'ean-for-woocommerce' ),
'desc_tip' => __( 'EAN list to assign from.', 'ean-for-woocommerce' ) . ' ' .
__( 'One EAN per line.', 'ean-for-woocommerce' ) . ' ' .
__( 'Used (i.e., assigned) EANs will be automatically removed from the list.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_assign_list',
'default' => '',
'type' => 'textarea',
'css' => 'height:100px;',
),
array(
'title' => __( 'Delete', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Delete all EANs for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_delete_product_meta',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Copy to product SKU', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Copy EAN to the product SKU for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[copy_to_sku]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Copy to product meta', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Copy EAN to the product meta for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[copy_to_meta]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => sprintf( __( 'Meta key, e.g.: %s, or comma-separated list of keys, e.g.: %s', 'ean-for-woocommerce' ), '<code>_gtin</code>', '<code>_gtin,_ean13</code>' ),
'desc_tip' => __( 'Product meta key to copy to.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_copy_to_meta[key]',
'default' => '',
'type' => 'text',
),
array(
'desc' => __( 'Meta sub key', 'ean-for-woocommerce' ) . ' (' . __( 'optional', 'ean-for-woocommerce' ) . ')',
'desc_tip' => __( 'Optional sub key. This is used when meta is saved in an array.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_copy_to_meta[sub_key]',
'default' => '',
'type' => 'text',
),
array(
'title' => __( 'Copy to product attribute', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Copy EAN to the product attribute for all products', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[copy_to_attr]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'desc' => __( 'Product attribute', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_copy_to_attr[product_attribute]',
'default' => '',
'type' => 'select',
'class' => 'chosen_select',
'options' => $this->get_product_attributes( __( 'Select attribute...', 'ean-for-woocommerce' ) ),
),
array(
'title' => __( 'Get stats', 'ean-for-woocommerce' ),
'desc_tip' => __( 'This tool will not assign/delete any EANs, instead it will count how many products in your shop do not have EAN.', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Get stats', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product[get_stats]',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Variable products', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Sets how variable products should be handled in all product tools.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_variable',
'default' => 'all',
'type' => 'select',
'class' => 'chosen_select',
'options' => array(
'all' => __( 'All (variable and variations)', 'ean-for-woocommerce' ),
'variations_only' => __( 'Variations only', 'ean-for-woocommerce' ),
'variable_only' => __( 'Variable only', 'ean-for-woocommerce' ),
),
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_tools_products',
),
array(
'title' => __( 'Product Actions', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_tools_products_actions',
),
array(
'title' => __( 'Automatic actions', 'ean-for-woocommerce' ),
'desc' => __( 'New product', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Sets actions to be automatically performed when new product is added.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_action_on_new',
'default' => '',
'type' => 'select',
'class' => 'chosen_select',
'options' => $this->get_product_actions_list(),
),
array(
'desc' => __( 'Update product', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Sets actions to be automatically performed when product is updated.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_product_action_on_update',
'default' => '',
'type' => 'select',
'class' => 'chosen_select',
'options' => $this->get_product_actions_list(),
),
array(
'title' => __( 'Periodic action', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Sets action to be automatically performed on a periodic basis (for all products).', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_products_periodic_action',
'default' => '',
'type' => 'select',
'class' => 'chosen_select',
'options' => $this->get_product_actions_list(),
),
array(
'desc' => __( 'Periodic action interval in seconds', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_products_periodic_action_interval',
'default' => 3600,
'type' => 'number',
'custom_attributes' => array( 'min' => 1 ),
),
array(
'title' => __( '"Products > Bulk actions"', 'ean-for-woocommerce' ),
'desc_tip' => __( 'Sets actions to be added to the "Products > Bulk actions" dropdown.', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_product_bulk_actions',
'default' => array( 'alg_wc_ean_delete', 'alg_wc_ean_generate' ),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => array(
'alg_wc_ean_generate' => __( 'Generate EAN', 'ean-for-woocommerce' ),
'alg_wc_ean_delete' => __( 'Delete EAN', 'ean-for-woocommerce' ),
),
),
array(
'desc' => __( 'Require confirmation?', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_product_bulk_actions_confirm',
'default' => array( 'alg_wc_ean_delete' ),
'type' => 'multiselect',
'class' => 'chosen_select',
'options' => array(
'alg_wc_ean_generate' => __( 'Generate EAN', 'ean-for-woocommerce' ),
'alg_wc_ean_delete' => __( 'Delete EAN', 'ean-for-woocommerce' ),
),
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_tools_products_actions',
),
array(
'title' => __( 'Order Tools', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => 'alg_wc_ean_tools_orders',
),
array(
'title' => __( 'Add', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Add EANs to all order items', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_orders_add',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Delete', 'ean-for-woocommerce' ),
'desc' => '<span class="dashicons dashicons-admin-generic"></span> ' . __( 'Delete EANs from all order items', 'ean-for-woocommerce' ),
'id' => 'alg_wc_ean_tool_orders_delete',
'default' => 'no',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => 'alg_wc_ean_tools_orders',
),
);
return $settings;
}
}
endif;
return new Alg_WC_EAN_Settings_Tools();

View File

@@ -0,0 +1,197 @@
<?php
/**
* EAN for WooCommerce - Settings
*
* @version 4.3.0
* @since 1.0.0
*
* @author Algoritmika Ltd
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Alg_WC_EAN_Settings' ) ) :
class Alg_WC_EAN_Settings extends WC_Settings_Page {
/**
* Constructor.
*
* @version 4.3.0
* @since 1.0.0
*/
function __construct() {
$this->id = 'alg_wc_ean';
$this->label = apply_filters( 'alg_wc_ean_settings_page_label', __( 'EAN', 'ean-for-woocommerce' ) );
parent::__construct();
// Sections
require_once( 'class-alg-wc-ean-settings-section.php' );
// Sections: EAN
require_once( 'class-alg-wc-ean-settings-general.php' );
require_once( 'class-alg-wc-ean-settings-tools.php' );
require_once( 'class-alg-wc-ean-settings-compatibility.php' );
// Sections: Barcodes
require_once( 'class-alg-wc-ean-settings-barcodes.php' );
require_once( 'class-alg-wc-ean-settings-barcodes-compatibility.php' );
new Alg_WC_EAN_Settings_Barcodes( '1d' );
new Alg_WC_EAN_Settings_Barcodes_Compatibility( '1d' );
new Alg_WC_EAN_Settings_Barcodes( '2d' );
new Alg_WC_EAN_Settings_Barcodes_Compatibility( '2d' );
// Sections: Print
require_once( 'class-alg-wc-ean-settings-print.php' );
if ( 'yes' === get_option( 'alg_wc_ean_print_products_list_section', 'no' ) && 'yes' === get_option( 'alg_wc_ean_print_barcodes_to_pdf', 'no' ) ) {
require_once( 'class-alg-wc-ean-settings-print-products.php' );
}
// Sections: Advanced
require_once( 'class-alg-wc-ean-settings-advanced.php' );
// Sections: Extra fields
require_once( 'class-alg-wc-ean-settings-extra-fields.php' );
require_once( 'class-alg-wc-ean-settings-extra-field.php' );
for ( $i = 1; $i <= get_option( 'alg_wc_ean_extra_fields_num_total', 0 ); $i++ ) {
new Alg_WC_EAN_Settings_Extra_Field( $i );
}
// Custom fields
add_action( 'woocommerce_admin_field_' . 'alg_wc_ean_file', array( $this, 'alg_wc_ean_file' ) );
}
/**
* alg_wc_ean_file.
*
* @version 3.1.0
* @since 3.1.0
*
* @see https://github.com/woocommerce/woocommerce/blob/6.1.1/plugins/woocommerce/includes/admin/class-wc-admin-settings.php#L720
*/
function alg_wc_ean_file( $value ) {
// Custom attribute handling.
$custom_attributes = array();
if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
}
}
// Description handling.
$field_description = WC_Admin_Settings::get_field_description( $value );
$description = $field_description['description'];
$tooltip_html = $field_description['tooltip_html'];
?><tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo $tooltip_html; // WPCS: XSS ok. ?></label>
</th>
<td class="forminp forminp-file">
<input
name="<?php echo esc_attr( $value['id'] ); ?>"
id="<?php echo esc_attr( $value['id'] ); ?>"
type="file"
style="<?php echo esc_attr( $value['css'] ); ?>"
value=""
class="<?php echo esc_attr( $value['class'] ); ?>"
placeholder=""
<?php echo implode( ' ', $custom_attributes ); // WPCS: XSS ok. ?>
/><?php echo esc_html( $value['suffix'] ); ?> <?php echo $description; // WPCS: XSS ok. ?>
</td>
</tr>
<?php
}
/**
* get_settings.
*
* @version 4.3.0
* @since 1.0.0
*/
function get_settings() {
global $current_section;
$reset_settings = ( 'print_products' === $current_section ? array() : array(
array(
'title' => __( 'Reset Settings', 'ean-for-woocommerce' ),
'type' => 'title',
'id' => $this->id . '_' . $current_section . '_reset_options',
),
array(
'title' => __( 'Reset section settings', 'ean-for-woocommerce' ),
'desc' => '<strong>' . __( 'Reset', 'ean-for-woocommerce' ) . '</strong>',
'desc_tip' => __( 'Check the box and save changes to reset.', 'ean-for-woocommerce' ),
'id' => $this->id . '_' . $current_section . '_reset',
'default' => 'no',
'type' => 'checkbox',
),
array(
'type' => 'sectionend',
'id' => $this->id . '_' . $current_section . '_reset_options',
),
) );
return array_merge( apply_filters( 'woocommerce_get_settings_' . $this->id . '_' . $current_section, array() ), $reset_settings );
}
/**
* maybe_reset_settings.
*
* @version 1.0.0
* @since 1.0.0
*/
function maybe_reset_settings() {
global $current_section;
if ( 'yes' === get_option( $this->id . '_' . $current_section . '_reset', 'no' ) ) {
foreach ( $this->get_settings() as $value ) {
if ( isset( $value['id'] ) ) {
$id = explode( '[', $value['id'] );
delete_option( $id[0] );
}
}
add_action( 'admin_notices', array( $this, 'admin_notices_settings_reset_success' ), PHP_INT_MAX );
}
}
/**
* admin_notices_settings_reset_success.
*
* @version 1.0.0
* @since 1.0.0
*/
function admin_notices_settings_reset_success() {
echo '<div class="notice notice-success is-dismissible"><p><strong>' .
__( 'Your settings have been reset.', 'ean-for-woocommerce' ) . '</strong></p></div>';
}
/**
* save.
*
* @version 4.3.0
* @since 1.0.0
*
* @todo (dev) `wp_safe_redirect`: better solution?
*/
function save() {
global $current_section;
parent::save();
$this->maybe_reset_settings();
do_action( 'alg_wc_ean_settings_saved', $current_section );
if ( 'print' === $current_section || 'advanced' === $current_section || 'extra_field' === substr( $current_section, 0, strlen( 'extra_field' ) ) ) {
wp_safe_redirect( add_query_arg( array() ) );
exit;
}
}
}
endif;
return new Alg_WC_EAN_Settings();

View File

@@ -0,0 +1,67 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.4\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: es_ES\n"
#: ean-for-woocommerce.php:152
msgid "Settings"
msgstr "Ajustes"
#: ean-for-woocommerce.php:155
msgid "Unlock All"
msgstr "Desbloquear Todo"
#: includes/class-alg-wc-ean-core.php:58
msgid "EAN:"
msgstr "EAN:"
#: includes/class-alg-wc-ean-core.php:76
#: includes/settings/class-alg-wc-ean-settings-general.php:43
#: includes/settings/class-alg-wc-ean-settings.php:24
msgid "EAN"
msgstr "EAN"
#: includes/class-alg-wc-ean-core.php:116
msgid "EAN barcode"
msgstr "Código de barras EAN"
#: includes/settings/class-alg-wc-ean-settings-general.php:24
msgid "General"
msgstr "General"
#: includes/settings/class-alg-wc-ean-settings-general.php:38
msgid "EAN Options"
msgstr "Opciones de EAN"
#: includes/settings/class-alg-wc-ean-settings-general.php:44
msgid "Enable plugin"
msgstr "Habilitar plugin"
#: includes/settings/class-alg-wc-ean-settings.php:38
msgid "Reset Settings"
msgstr "Reiniciar ajustes"
#: includes/settings/class-alg-wc-ean-settings.php:43
msgid "Reset section settings"
msgstr "Restablecer configuración de sección"
#: includes/settings/class-alg-wc-ean-settings.php:44
msgid "Reset"
msgstr "Reiniciar"
#: includes/settings/class-alg-wc-ean-settings.php:45
msgid "Check the box and save changes to reset."
msgstr "Marque la casilla y guarde los cambios para restablecer."
#: includes/settings/class-alg-wc-ean-settings.php:84
msgid "Your settings have been reset."
msgstr "Su configuración ha sido restablecida."

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,660 @@
=== EAN for WooCommerce ===
Contributors: wpcodefactory, algoritmika, anbinder, karzin, omardabbas, kousikmukherjeeli
Tags: woocommerce, ean, gtin, barcode, woo commerce
Requires at least: 4.4
Tested up to: 6.4
Stable tag: 4.8.3
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Manage product GTIN (EAN, UPC, ISBN, etc.) in WooCommerce. Beautifully.
== Description ==
**EAN for WooCommerce** plugin lets you manage product GTIN (EAN, UPC, ISBN, etc.) in WooCommerce.
Currently supported standards: EAN-13, UPC-A, EAN-8, ISBN-13, JAN, EAN-14, Custom.
### &#9989; Main Features ###
* **Save product's EAN** in backend.
* For **variable products** set EAN for each variation individually or set single EAN for all variations at once.
* **Search by EAN** in backend (including AJAX search) and in frontend.
* Add sortable EAN column to **admin products list**.
* Optionally **show EAN** on **single product page**, **shop pages** and/or in **cart** on frontend.
* Add EAN to **product structured data**, e.g., for Google Search Console.
* Add EAN to **WooCommerce REST API** order and product responses; search orders and products by EAN.
* Show EAN in **order items table**, including emails, "thank you" page, etc.
* **Export** and **import** EAN.
* Use product **quick** and **bulk edit** to manage EAN.
* Output EAN with a **shortcode**.
* And more...
### &#129520; Tools ###
Plugin has tools that will help you generate, copy, assign and delete EANs in bulk, automatically or periodically.
* **Generate** EANs automatically with customizable EAN type, country prefix(es) and seed.
* **Copy** EANs **from** product **SKU**, product **ID** or product **meta**.
* **Assign** EANs from the predefined **list**.
* **Delete** EANs for all products at once.
* **Copy** EANs **to** product **SKU** or product **attribute**.
* **Add** or **delete** EANs for all **orders** at once.
* And more...
### &#129309; Compatibility ###
* [Google Listings & Ads](https://wordpress.org/plugins/google-listings-and-ads/) plugin.
* [Point of Sale for WooCommerce](https://woocommerce.com/products/point-of-sale-for-woocommerce/) plugin.
* [Woocommerce OpenPos](https://codecanyon.net/item/openpos-a-complete-pos-plugins-for-woocomerce/22613341) plugin.
* [Dokan marketplace](https://wordpress.org/plugins/dokan-lite/) plugin.
* [WCFM](https://wordpress.org/plugins/wc-frontend-manager/) and [WCFM Marketplace](https://wordpress.org/plugins/wc-multivendor-marketplace/) plugins.
* [MultiVendorX](https://wordpress.org/plugins/dc-woocommerce-multi-vendor/) plugin.
* [Print Invoice & Delivery Notes for WooCommerce](https://wordpress.org/plugins/woocommerce-delivery-notes/) plugin.
* [WooCommerce PDF Invoices & Packing Slips](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/) plugin.
* [WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels](https://wordpress.org/plugins/print-invoices-packing-slip-labels-for-woocommerce/) plugin.
* [WooCommerce Google Product Feed](https://woocommerce.com/products/google-product-feed/) plugin.
* [Rank Math SEO](https://wordpress.org/plugins/seo-by-rank-math/) plugin.
* [WooCommerce Customer / Order / Coupon Export](https://woocommerce.com/products/ordercustomer-csv-export/) plugin.
* And more...
### &#127942; Premium Version ###
With [premium plugin version](https://wpfactory.com/item/ean-for-woocommerce/) you can:
* Generate and display **barcode image** for your product EAN (frontend, backend, order items table (including emails), REST API, etc.).
* Barcodes can be **one-dimensional** (1D barcodes) or **two-dimensional** (2D barcodes, QR codes).
* Additionally you can **print** multiple EANs and barcodes to **PDF** file.
* Add multiple **extra fields**, e.g., single product can have **EAN** and **MPN** fields **simultaneously**.
### &#128472; Feedback ###
* We are open to your suggestions and feedback. Thank you for using or trying out one of our plugins!
* [Visit plugin site](https://wpfactory.com/item/ean-for-woocommerce/).
### &#8505; More ###
* The plugin is **"High-Performance Order Storage (HPOS)"** compatible.
== Installation ==
1. Upload the entire plugin folder to the `/wp-content/plugins/` directory.
2. Activate the plugin through the "Plugins" menu in WordPress.
3. Start by visiting plugin settings at "WooCommerce > Settings > EAN".
== Screenshots ==
1. EAN for WooCommerce - Backend - Simple product
2. EAN for WooCommerce - Backend - Variable product
3. EAN for WooCommerce - Frontend - Variable product
4. EAN for WooCommerce - Admin settings
5. EAN for WooCommerce - Tools
== Changelog ==
= 4.8.3 - 09/11/2023 =
* Dev - Tools - Product Tools - Copy to product meta - "Meta sub key (optional)" option added.
* Tested up to: 6.4.
= 4.8.2 - 20/10/2023 =
* Dev - REST API - Orders - Add EAN to each order object in REST API responses - Extra checks added to prevent possible PHP warning.
= 4.8.1 - 19/10/2023 =
* Dev - Admin settings - General - Admin product edit page - Add pattern - Description updated.
* WC tested up to: 8.2.
= 4.8.0 - 05/10/2023 =
* Dev - General - Admin product edit page - Add pattern - Default value changed to `no`.
= 4.7.9 - 25/09/2023 =
* Plugin icon, banner updated.
= 4.7.8 - 25/09/2023 =
* Fix - Admin settings - Compatibility - Google Listings & Ads - Typo fixed.
= 4.7.7 - 19/09/2023 =
* Dev - Compatibility - Google Listings & Ads - Different approach implemented.
= 4.7.6 - 15/09/2023 =
* Dev - Search - Code refactoring.
* Dev - Pro - Extra Fields - "Admin product search" options added (default to `no`).
* Dev - Pro - Extra Fields - "Search" (frontend) options added (default to `no`).
* WC tested up to: 8.1.
= 4.7.5 - 05/09/2023 =
* Dev - Compatibility - "Google Listings & Ads" option added.
* Dev - Developers - `alg_wc_ean_product_structured_data_value` filter added.
* Dev - Developers - `alg_wc_ean_product_structured_data_markup_value` filter added.
* Dev - Developers - `alg_wc_ean_product_structured_data_allow_empty_value` filter added.
= 4.7.4 - 30/08/2023 =
* Dev - Pro - Print - Cell - "Cell top/left/right/bottom margin" options added (all default to `0`).
* Dev - Pro - Print - Cell - "Cell content alignment" option added.
* Dev - Pro - Print - Admin settings descriptions updated.
= 4.7.3 - 23/08/2023 =
* Fix - Declaring HPOS compatibility for the free plugin version, even if the Pro version is activated.
* Dev - Compatibility - "MultiVendorX" options added.
* Dev - Admin settings - Advanced - Meta key - Description updated.
= 4.7.2 - 09/08/2023 =
* Fix - Tools - Product Tools - Assign from the list - Product categories - Variations - Checking for the `variable` product type.
* Dev - Tools - Product Tools - Assign from the list - Product categories - Variations - Ensuring that products are always sorted by ID (ASC).
* Tested up to: 6.3.
* WC tested up to: 8.0.
= 4.7.1 - 15/07/2023 =
* Fix - Search / Admin product search / Admin products list column (sorting) - Handling cases when `query['post_type']` is an array.
= 4.7.0 - 13/07/2023 =
* Dev - "EAN-14" type added.
* Dev - Code refactoring.
= 4.6.0 - 23/06/2023 =
* Dev - Display - Shortcodes are now processed in the "Single product page" and "Shop pages" options.
* Dev - Display - Shop pages - "Template" option added. Defaults to `EAN: %ean%`.
* Dev - Tools - Product Tools - Copy from product attribute - "Custom product attribute" option added.
* Dev - Shortcodes - `[alg_wc_ean_if]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_if_product_cat]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_if_product_tag]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_product_terms]` shortcode added.
= 4.5.1 - 18/06/2023 =
* WC tested up to: 7.8.
= 4.5.0 - 07/06/2023 =
* Dev "High-Performance Order Storage (HPOS)" compatibility.
* Dev - Admin Settings - Option descriptions updated.
* Dev - Code refactoring.
* WC tested up to: 7.7.
= 4.4.6 - 02/05/2023 =
* Dev - Shortcodes - `[alg_wc_ean_is_valid]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_is_unique]` shortcode added.
* Dev - Compatibility - Dokan - "Description" option added.
* Dev - Compatibility - Dokan - "Required HTML" option added.
* WC tested up to: 7.6.
= 4.4.5 - 06/04/2023 =
* Fix - Display - Frontend hooks (including barcodes) now are loaded on AJAX as well.
* Dev - Developers - REST API - `alg_wc_ean_rest_api_product_ean_key` filter added.
* Dev - Developers - REST API - `alg_wc_ean_rest_api_order_ean_key` filter added.
* Dev - Admin Settings - General - Option descriptions updated.
* Tested up to: 6.2.
* WC tested up to: 7.5.
= 4.4.4 - 02/02/2023 =
* Dev - Developers - Admin product search - `alg_wc_ean_search_backend` filter added.
* Dev - Developers - Search - `alg_wc_ean_search` filter added.
* WC tested up to: 7.3.
= 4.4.3 - 10/01/2023 =
* Dev - Shortcodes - `[alg_wc_ean_product_image]` - Security - `height` and `width` attributes are escaped now.
* WC tested up to: 7.2.
= 4.4.2 - 26/11/2022 =
* Dev - Tools - Product Tools - "Copy from product attribute" tool added.
= 4.4.1 - 25/11/2022 =
* Dev - Compatibility - Dokan - "Required" option added (defaults to `no`).
* WC tested up to: 7.1.
* Tested up to: 6.1.
= 4.4.0 - 20/10/2022 =
* Dev - General - Admin product edit page - "Require" option added. Defaults to `no`.
* Dev - General - Admin product edit page - "Add pattern" option added. Defaults to `yes`.
* Dev - Advanced - JavaScript Variation Options - "Variations form" option added. Defaults to `.variations_form`.
* WC tested up to: 7.0.
= 4.3.4 - 28/09/2022 =
* Dev - General - Admin product edit page - "Position (variation product)" option added. Defaults to "Variations: After pricing".
* WC tested up to: 6.9.
= 4.3.3 - 08/09/2022 =
* Fix - Tools - Product Tools - Assign from the list - Product categories - Variations category filtering fixed.
= 4.3.2 - 29/08/2022 =
* Dev - REST API - Products - Add EAN to each product object in REST API responses - EAN added to variation responses as well.
= 4.3.1 - 15/08/2022 =
* Dev - Pro - Print/Barcode Generator - Now checking if classes exist before including the TCPDF library.
* WC tested up to: 6.8.
= 4.3.0 - 03/08/2022 =
* Dev - REST API - Products - Search by EAN - Now including product variations as well.
* Dev - Pro - Print - Print Tools - "Products List" tool added.
* Dev - Pro - Print - Admin Options - Print buttons - Quantity input - "Products > Bulk actions > Each product" option added.
* Dev - Pro - Extra Fields - Admin settings section description updated.
= 4.2.0 - 27/07/2022 =
* Dev - Compatibility - "Woocommerce OpenPos" compatibility added ("EAN" field is now available in "POS > Setting > Barcode Label > Barcode Meta Key").
* Dev - Compatibility - WooCommerce PDF Invoices & Packing Slips - "Content" options added. Includes barcodes.
* Dev - Pro - Code refactoring:
* Barcode Generator.
* Shortcodes - `[alg_wc_ean_barcode]` and `[alg_wc_ean_barcode_2d]`.
* WC tested up to: 6.7.
= 4.1.2 - 17/06/2022 =
* Dev - Tools - Product Actions - Bulk actions - "Require confirmation?" option added (defaults to "Delete EAN").
* Fix - Pro - Print - Print Tools - Quantity - Quantity input was ignored when products had identical EANs.
* Dev - Pro - Print - Admin Options - Print buttons - "Quantity input" option added.
= 4.1.1 - 16/06/2022 =
* Fix - Admin product search - Including all post statuses now (e.g., drafts).
* Dev - Tools - Product Tools - Copy to product meta - Meta key - Comma-separated list of keys is now accepted.
= 4.1.0 - 16/06/2022 =
* Dev - Tools - Product Tools - "Copy to product meta" tool added.
* Dev - Shortcodes - `[alg_wc_ean_product_sku]` - Optional `max_length` attribute added.
* Dev - Pro - Print - Print Tools - "Print" tool added.
* Dev - Pro - Developers - Print - `alg_wc_ean_print_get_products` filter added.
* WC tested up to: 6.6.
= 4.0.0 - 10/06/2022 =
* Dev - General - Admin product edit page - 'Add "Generate" button' option added.
* Dev - Compatibility - WCFM - Variations are supported now.
* Dev - Compatibility - WCFM - 'Add "Generate" button' option added.
* Dev - Advanced - Export/Import Plugin Settings - "Reset" tool added.
* Dev - Advanced - Export/Import Plugin Settings - Code refactoring.
* Dev - Shortcodes - `[alg_wc_ean_product_author_id]` shortcode added.
* Dev - Developers - Tools - Product Tools - Generate:
* `alg_wc_ean_product_tools_generate_ean_country_prefix` filter added.
* `alg_wc_ean_product_tools_generate_ean_seed_prefix` filter added.
* `alg_wc_ean_product_tools_generate_ean_seed` filter added.
* Dev - Pro - "Extra Fields" sections added.
* Dev - Pro - Shortcodes - Barcodes - `img_w` and `img_h` attributes added (both defaults to `false`).
= 3.9.1 - 24/05/2022 =
* Dev - Print - Admin settings rearranged.
* Tested up to: 6.0.
= 3.9.0 - 16/05/2022 =
* Dev - Tools - Product Tools:
* "Copy to product SKU" tool added.
* "Copy to product attribute" tool added.
* "Variable products" option added.
* Generate - "Seed" options added (defaults to "Product ID").
* Admin settings descriptions updated.
* Code refactoring.
* Dev - Developers - `alg_wc_ean_display` filter added.
* WC tested up to: 6.5.
= 3.8.0 - 07/04/2022 =
* Dev - Compatibility:
* Point of Sale for WooCommerce - "Add EAN to search" option added.
* "WooCommerce Customer / Order / Coupon Export" plugin compatibility added. Includes barcodes.
* Dev - Barcodes:
* "[2D] Barcode (image link)" and "[2D] Barcode (base64)" columns added to "Products > All Products > Export".
* Barcode generator - Always checking if EAN is valid for 1D barcodes.
* Dev - Advanced - Export/Import Plugin Settings - Import:
* Validating JSON data now.
* Resetting all options before the import now.
* Dev - Shortcodes - Barcodes - Template:
* `%barcode_base64%` placeholder added.
* `%barcode_link%` placeholder added.
* Dev - Developers - Product structured data - `alg_wc_ean_product_structured_data_markup_key`:
* `$product` is passed to the filter as well now.
* Filter is applied for the "Custom key" option as well now.
* Dev - Admin settings:
* General - "Admin search" renamed to "Admin product search".
* Barcodes - "Advanced Options" renamed to "Advanced Barcodes Options".
* Barcodes - "Compatibility" moved to separate sections.
* Print - "Advanced Options" renamed to "Advanced Print Options".
* Dev - Code refactoring:
* EAN edit.
* Export Plugin Settings.
* Barcode generator.
= 3.7.2 - 22/03/2022 =
* Dev - Tools - Product Tools - Generate - "Product attribute (optional)" option added.
= 3.7.1 - 21/03/2022 =
* Dev - Tools - Product Tools - Copy product meta - "Meta sub key (optional)" option added.
= 3.7.0 - 21/03/2022 =
* Dev - Single product page - Positions - "Product additional information tab" position added.
* Dev - Product structured data - "Rank Math SEO" option added (defaults to `no`).
* Dev - Barcodes - Cart:
* Using shortcodes now.
* "Cart template" option added.
* Dev - REST API:
* Products - "Search by EAN" option added.
* Orders - "Search by EAN" option added.
* Admin settings descriptions updated.
* Dev - Tools:
* Product Tools - "Get stats" tool added.
* Product Tools - "... total products" message added.
* Product Tools - Assign from the list - "Reuse deleted" option added (defaults to `no`).
* Dev - Shortcodes - Barcodes - `[alg_wc_ean_barcode_2d_base64]` - Default `w` and `h` are set to `2` now (was `3`).
* Dev - "TCPDF" library updated to v6.4.4.
* Dev - Code refactoring:
* `Alg_WC_EAN_REST_API` class added.
* `Alg_WC_EAN_Order_Items_Table` class added.
* `Alg_WC_EAN_Order_Items_Table_Barcodes` class added.
* `Alg_WC_EAN_Barcodes` class added.
* WC tested up to: 6.3.
= 3.6.0 - 03/03/2022 =
* Dev - General - Admin product edit page - "Check if valid" option added (defaults to `yes`).
* Dev - General - Admin product edit page - "Check if unique" option added (defaults to `no`).
* Dev - General - "Admin product duplicate" option added (defaults to `yes`).
* Dev - Shortcodes - `[alg_wc_ean_product_meta]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_product_function]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean]` - `children` attribute (defaults to `no`) and `glue` attribute (defaults to `, `) added.
* Dev - Developers - `alg_wc_ean_edit` filter added.
* Dev - Print - "Style" option added.
* Dev - Barcodes - Shortcodes - `on_empty` attribute added to `[alg_wc_ean_barcode]`, `[alg_wc_ean_barcode_2d]`, `[alg_wc_ean_barcode_base64]` and `[alg_wc_ean_barcode_2d_base64]` shortcodes.
* Dev - Admin settings rearranged ("Orders & Emails" subsections added (includes barcodes)).
* Dev - Code refactoring.
= 3.5.1 - 25/02/2022 =
* Dev - Compatibility - "WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels" (includes barcodes):
* "Position" option added (defaults to "After item meta" (was "After item name")). Available positions: "Before item name", "After item name", "After item meta", "Before item meta" and "As a separate column".
* "Documents" option added (defaults to all documents (was "Invoice" and "Dispatch label" only)).
* "Column title", "Column HTML class" and "Column HTML style" options added.
= 3.5.0 - 24/02/2022 =
* Dev - Compatibility - "WooCommerce PDF Invoices, Packing Slips, Delivery Notes and Shipping Labels" plugin compatibility added. Includes barcodes.
* Dev - Shortcodes - `[alg_wc_ean]` - `on_empty` attribute added.
* Dev - Shortcodes - `[alg_wc_ean_product_attr]` - `product_id`, `before`, `after`, `parent` attributes added. Shortcode moved to the free plugin version.
* Dev - Shortcodes - `[alg_wc_ean_product_image]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_product_name]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_product_sku]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_product_price]` shortcode added.
* Dev - Shortcodes - `[alg_wc_ean_product_id]` shortcode added.
* Dev - Barcodes - Shortcodes - `color` attribute added to `[alg_wc_ean_barcode]`, `[alg_wc_ean_barcode_2d]`, `[alg_wc_ean_barcode_base64]` and `[alg_wc_ean_barcode_2d_base64]` shortcodes (defaults to `#000000`).
* Dev - Print - "Cell border" option added (defaults to "No").
* Dev - Print - Placeholders are deprecated now (shortcodes should be used instead). Default value and admin settings description updated for the "Template" option. Now "Barcode Options", "2D Barcode Options" and "Product Image Options" admin settings subsections are visible only if there is corresponding placeholder in the "Template".
* Dev - Admin settings descriptions updated.
* Dev - Code refactoring.
= 3.4.0 - 23/02/2022 =
* Dev - General - Product structured data - "Automatic key" options added.
* Dev - General - Type - Type details - Admin settings restyled.
* Dev - Tools - Product Tools - Generate - Type - Admin settings description added.
* Dev - Barcodes - Shortcodes - Optional `ean` attribute added.
* Dev - Barcodes - Shortcodes - Shortcodes are always available now (even if the corresponding barcodes section is disabled), e.g., for the "Print" section.
* Dev - Print - Developers - `alg_wc_ean_print_render_meta_box_shop_order_force_refunded` filter added.
* Dev - Print - Developers - `alg_wc_ean_print_barcode_shop_order_refunded_item_qty` filter added.
* Dev - Code refactoring.
= 3.3.0 - 21/02/2022 =
* Dev - General - Type - "ISBN-13" type added.
* Dev - General - Type - "JAN" type added.
* Dev - General - Type - "Custom" type added; "CODE 128" type removed.
* Dev - General - Type - "Type details" description added.
* Dev - Tools - Product Tools - Generate - "County prefix length" option added (for EAN-8 type only).
* Dev - 1D Barcodes - Advanced Options - "Barcode type" option added (defaults to `Automatic`).
* Dev - Code refactoring.
= 3.2.0 - 15/02/2022 =
* Dev - Orders - REST API - Now using current product EAN as a fallback (i.e., if there is no EAN in order item meta).
* Dev - Barcodes - "Orders" options added ("Show barcode image on admin order edit page").
* Dev - Barcodes - "REST API" (product and order) options added.
* Dev - Barcodes - `[alg_wc_ean_barcode_base64]` and `[alg_wc_ean_barcode_2d_base64]` shortcodes added.
* Dev - Admin settings rearranged: "REST API" subsections added.
* Dev - Code refactoring.
= 3.1.2 - 11/02/2022 =
* Dev - Compatibility - Dokan - Field added to variations. Includes barcodes.
* Dev - Compatibility - WooCommerce PDF Invoices & Packing Slips - "Position" option added (defaults to "After item meta"). Includes barcodes.
* Dev - Deploy script added.
* WC tested up to: 6.2.
= 3.1.1 - 04/02/2022 =
* Dev - Print - Template - `%product_price_regular%`, `%product_price_sale%`, `%product_price_regular_raw%`, `%product_price_sale_raw%` placeholders added.
= 3.1.0 - 04/02/2022 =
* Dev - Advanced - "Export/Import Plugin Settings" options added.
* Dev - Advanced - Meta key - Option mark as "required" now.
* Dev - Order items table - Pages - Outputting barcode directly now (i.e., will work on `localhost` environment now). "Advanced > Force remote image" option added.
* Dev - Order items table - "Emails" options added. Includes barcodes.
* Dev - Order items table - "Template" options ("HTML" and "Plain text (emails only)") added.
* Dev - Print - Template - `%product_price%` and `%product_price_raw%` placeholders added.
* Tested up to: 5.9.
= 3.0.0 - 20/01/2022 =
* Dev - Single product page - Variable products - Safe-checks added in `variations_add_params()` function. Fixes the compatibility issue with the "WooCommerce Bulk Variations" plugin.
* Dev - Admin products list column - `width: 10%` style added.
* Dev - Compatibility - "WooCommerce Google Product Feed" plugin compatibility added.
* Dev - Tools - Assign from the list - "Product categories" option added.
* Dev - Barcodes - Compatibility - "Dokan" options added.
* Dev - Print - Print buttons - Single order - Using order item quantities now (and ignoring "Use stock quantity" option).
* Dev - Print - Print buttons - Single order - "Refunded items" buttons added.
* Dev - Print - Print buttons - "Variations print buttons" option added (defaults to `Variations tab`).
* Dev - Print - Page format - Dimensions added to the format descriptions.
* Dev - Print - Page format - Custom - Now using `LETTER` as a fallback, in case if custom width or height is set to `0` (zero).
* Dev - Code refactoring.
* WC tested up to: 6.1.
= 2.9.0 - 24/12/2021 =
* Fix - Text domain (translation) fixed.
* Fix - Tools - Product Tools - Automatic actions - Variations update fixed.
* Dev - General - "REST API" (product) option added.
* Dev - Tools - Product Tools - "Periodic action" options added.
* Dev - Tools - Product Tools - "Assign EAN from the list for all products" tool added.
* Dev - Tools - Product Tools - "Automatic actions" options added ("Automatically generate EAN for new products / on product update" options removed).
* Dev - Tools - Product Tools - Automatic actions - "Copy product SKU", "Copy product ID", "Copy product meta" actions added.
* Dev - Tools - Product Tools - Automatic actions - Hook priority increased (from `10` to `PHP_INT_MAX`).
* Dev - Tools - Product Tools - Products are sorted by ID (ascending) now.
* Dev - Tools - Product Tools - Settings restyled.
* Dev - Print - Print buttons - "Print buttons style" option added.
* Dev - Code refactoring.
* Plugin description improved.
= 2.8.0 - 16/12/2021 =
* Dev - General - Shop pages - Now using "Title" option in the template.
* Dev - General - Orders - "REST API" option added.
* Dev - Advanced - "Meta key" option added.
* WC tested up to: 6.0.
= 2.7.0 - 12/11/2021 =
* Dev - Tools - Product Tools - Generate - "Seed prefix" option added (optional). "Prefix" options renamed to "Country prefix".
* Dev - Tools - Product Tools - "Products > Bulk actions" option added (defaults to "Generate EAN" and "Delete EAN" actions).
* Dev - Print - "Print barcode" (i.e., vs "Get barcode PDF") buttons added.
* Dev - Print - Advanced Options - "Use Print.js" option added.
* Dev - Print - Advanced Options - "Skip products without EAN" option added.
* Dev - Print - Print buttons - Single product - Separate variation buttons added.
* Dev - Print - Shortcodes - `[alg_wc_ean_product_attr]` shortcode added.
* Dev - Print - Placeholders - `%product_parent_title%` placeholder added.
* Dev - Print - Placeholders - `%product_parent_sku%` placeholder added.
* Dev - Print - Placeholders - `%product_parent_id%` placeholder added.
* Dev - Print - Admin settings restyled.
* Dev - Barcodes - Shortcodes - `content` - `sku` value added.
* WC tested up to: 5.9.
= 2.6.0 - 03/11/2021 =
* Dev - Compatibility - "WooCommerce PDF Invoices & Packing Slips" plugin compatibility options added.
* Dev - Compatibility - Print Invoice & Delivery Notes for WooCommerce - Using our "General > Title" option value in PDFs now.
* Dev - Print - Print buttons - "Single order" option added.
* Dev - Print - Print buttons - "Single product" option added.
* Dev - Print - "Print buttons" option added (defaults to `Products > Bulk actions`).
* Dev - Print - Template - `%product_sku%` placeholder added.
* Dev - Print - Template - `%product_image%` - Now checking if `curl_init()` function exists. This prevents critical PHP error.
* Dev - Admin settings description updated.
* Dev - Code refactoring.
= 2.5.0 - 28/10/2021 =
* Dev - Print - "Font" and "Font size" options added. "DejaVu Sans (Unicode)" font added (normal only; italic and bold were not added to reduce the size of the plugin). All other available fonts (i.e., "Times New Roman", "Helvetica" and "Courier") have italic and bold included.
* WC tested up to: 5.8.
= 2.4.2 - 30/09/2021 =
* Dev - Search - "Flatsome" theme - Allowing partial EAN matches now.
= 2.4.1 - 29/09/2021 =
* Fix - Possible PHP parse error fixed.
= 2.4.0 - 27/09/2021 =
* Dev - Developers - `alg_wc_ean_get_type` filter added.
* Dev - Admin settings description updated.
* Dev - 1D Barcodes - Checking if EAN is valid before generating the barcode now.
* Dev - Print - Template - `%type%` placeholder added (mostly for debugging).
* Dev - Code refactoring.
= 2.3.0 - 23/09/2021 =
* Dev - Search - Safe checks added (checking for the valid `$post` variable now).
= 2.2.9 - 22/09/2021 =
* Dev - General/Barcodes - Single product page - "Variable products: Position in variation" option added.
* Dev - Compatibility - Admin settings rearranged: moved to a separate settings section.
* Dev - Advanced - "JS selector in variation" option added.
* WC tested up to: 5.7.
= 2.2.8 - 20/09/2021 =
* Dev - Tools - Product Tools - Generate - "Automatically generate EAN for new products" option added.
* Dev - Tools - Product Tools - Generate - "Automatically generate EAN on product update" option added.
* Dev - Tools - Product Tools - "Copy EAN from product meta for all products" tool added.
* Dev - Tools - Product Tools - Not overwriting EANs for products with existing EAN now.
* Dev - Developers - `alg_wc_ean_settings_page_label` filter added.
= 2.2.7 - 16/09/2021 =
* Dev - General - "Title" option added.
* Dev - Tools - Product Tools - Generate - "Prefix to" option added (optional). "Prefix" option renamed to "Prefix from".
* Dev - Tools - Product Tools - Generate - Code refactoring.
= 2.2.6 - 15/09/2021 =
* Dev - Tools - Product Tools - Generate - "Type" option added.
* Dev - Tools - Product Tools - Generate - "Prefix" option added.
* Dev - Tools - Product Tools - Generate - Code refactoring.
* Dev - Tools - Admin settings restyled.
= 2.2.5 - 14/09/2021 =
* Fix - General - Admin products list column - Validate - Fixed.
* Dev - Tools - "Generate EAN for all products" tool added.
* Dev - Tools - "Copy EAN from product SKU for all products" tool added.
* Dev - Tools - Copy EAN from product ID for all products - Showing the tool for all EAN types now (not only for `CODE 128`).
* Dev - Tools - Admin settings rearranged: moved to a separate settings section. Settings descriptions updated.
* Dev - Barcodes - Outputting barcodes even for non-valid EANs now.
= 2.2.4 - 07/09/2021 =
* Fix - Print - Page format - Custom Width/Height - Admin settings description fixed.
* Dev - Print - Advanced - "Suppress errors" option added (defaults to `yes`).
* Dev - Print - General - "Page break margin" option added.
* Dev - Print - General - All margins (top/left/right) can be zero now.
* Dev - Print - Admin settings rearranged: "Unit" option moved higher.
* Dev - Print - Admin settings descriptions updated.
* Dev - Barcodes - Advanced - "Suppress errors" options added (defaults to `yes`).
= 2.2.3 - 31/08/2021 =
* Dev - Barcodes - Shortcodes - `content` - `add_to_cart` value added.
* Dev - Barcodes - Shortcodes - `content` - `add_to_cart_url` value added.
* WC tested up to: 5.6.
= 2.2.2 - 04/08/2021 =
* Dev - Plugin Compatibility Options - "Dokan" options added.
* Dev - Plugin Compatibility Options - "WCFM" options added.
* Dev - Admin settings restyled.
= 2.2.1 - 01/08/2021 =
* Fix - Search - Our frontend search option caused issues on WooCommerce Analytics page, e.g., when searching for a coupon code in filter. This is fixed now.
* Fix - Admin settings - "Undefined property" PHP notice fixed. Was occurring in "General" settings section, when "Enable plugin" option was disabled.
* WC tested up to: 5.5.
* Tested up to: 5.8.
= 2.2.0 - 28/06/2021 =
* Dev - Print - General Options - "Use quantity" option added.
* Dev - Print - General Options - Template - `%product_name%` and `%product_title%` placeholders added.
* Dev - Compatibility - Point of Sale for WooCommerce - EAN field added to the "Register > Scanning Fields" option.
* Dev - Admin settings descriptions updated.
* Dev - Code refactoring.
* Dev - "PHP Barcode Generator" library removed.
* Dev - "TCPDF" library updated to v6.4.1 (from v6.3.5).
* WC tested up to: 5.4.
= 2.1.1 - 23/03/2021 =
* Dev - 2D Barcodes - Advanced Options - "Barcode type" option added (defaults to `QR code: Low error correction`).
= 2.1.0 - 19/03/2021 =
* Fix - Print - `%barcode_2d%` - Barcode dimension fixed (was `1d`).
* Dev - General - "Orders" options ("Add EAN to new order items meta" and "Admin order") added.
* Dev - General - Tools - "Delete EANs from all order items" tool added.
* Dev - General - Tools - "Add EANs to all order items" tool added.
* Dev - General - Tools - "Delete all EANs for all products" tool added.
* Dev - General - Tools - "Generate EANs automatically for all products from product IDs" tool added (for `CODE 128` type only).
* Dev - General - Single product page - "Template" option added.
* Dev - General - Single product page - "Position", "Position priority" options added.
* Dev - General - Search - "Flatsome theme" option added.
* Dev - Barcodes - Admin products list column - "Column title" option added.
* Dev - Barcodes - Admin products list column - "Column template" options added. Defaults to barcodes **including product children**.
* Dev - Barcodes - Shortcodes - Checking if EAN is valid now (when `content` is set to `ean`).
* Dev - Barcodes - Shortcodes - `children` (defaults to `no`) and `glue` (defaults to empty string) attributes added. This will implode all variation barcodes for variable product.
* Dev - Barcodes - Shortcodes - `template` attribute added (defaults to `%barcode_img%`). Additional placeholders: `%product_id%`, `%product_title%`, `%value%`.
* Dev - Barcodes - Shortcodes - `content` attribute added. Defaults to `ean`. Other possible values: `url`, `admin_url`, `admin_search`, `increase_stock` and `decrease_stock`.
* Dev - Barcodes - Shortcodes - `w` and `h` attributes added.
* Dev - Barcodes - Shortcodes - `product_id` defaults to `get_the_ID()` now.
* Dev - Barcodes - Shortcodes - Now accessible in "Print barcodes (PDF)" section (i.e., in "Template" option).
* Dev - Print - General Options - "Variations" option added.
* Dev - Code refactoring.
* WC tested up to: 5.1.
* Tested up to: 5.7.
= 2.0.0 - 10/01/2021 =
* Dev - "Shop pages" options added.
* Dev - "Cart" options added.
* Dev - Shortcodes - `[alg_wc_ean_barcode]` - Shortcode is now available even if "Barcodes > Single product page" option is disabled.
* Dev - Shortcodes - `[alg_wc_ean_barcode_2d]` shortcode added.
* Dev - "2D Barcodes" section added.
* Dev - "Print" section added.
* Dev - Barcodes - "Admin products list column" options added.
* Dev - Barcodes - "Enable section" option added (defaults to `no`).
* Dev - Localization - `load_plugin_textdomain` moved to the `init` action.
* Dev - Settings - All barcode options moved to new "Barcodes" section, subsections merged, etc.
* Dev - Settings - Print Invoice & Delivery Notes for WooCommerce - Link updated.
* Dev - Code refactoring.
* WC tested up to: 4.8.
* Tested up to: 5.6.
= 1.5.1 - 29/11/2020 =
* Dev - `[alg_wc_ean]` shortcode added.
* Dev - `[alg_wc_ean_barcode]` shortcode added.
= 1.5.0 - 24/11/2020 =
* Dev - Type - "Automatic (EAN-13, UPC-A, EAN-8)" option added.
* Dev - EAN field added to the WooCommerce Export and Import tools.
* Dev - EAN field added to the WooCommerce Quick and Bulk edit.
* Dev - Backend Options - Product list column - Column is sortable now.
= 1.4.0 - 24/11/2020 =
* Dev - "Type" option added. Now (in addition to the default `EAN-13`) these types are available: `CODE 128`, `EAN-8`, `UPC-A`.
* Dev - "Print Invoice & Delivery Notes for WooCommerce" plugin options added.
* WC tested up to: 4.7.
= 1.3.0 - 28/10/2020 =
* Fix - Frontend - Show barcode - Variations - It only worked if "Show EAN" option was also enabled. This is fixed now.
* Dev - Free plugin version released.
* WC tested up to: 4.6.
= 1.2.0 - 13/10/2020 =
* Dev - "Order Items Table" options added.
* Dev - Frontend - Translation domain fixed.
= 1.1.1 - 09/09/2020 =
* Dev - Backend - "Position" option added.
* WC tested up to: 4.5.
= 1.1.0 - 27/08/2020 =
* Fix - Displaying variations codes for variable products with no *main* EAN set - Fixed.
* Dev - JS files minified.
* Dev - Admin settings descriptions updated.
* Dev - Code refactoring.
* Tested up to: 5.5.
* WC tested up to: 4.4.
= 1.0.3 - 14/01/2020 =
* Fix - Backend - Search - `meta_query` fixed.
= 1.0.2 - 08/01/2020 =
* Dev - Backend - Search - "AJAX search" option added.
* Dev - Code refactoring.
= 1.0.1 - 05/01/2020 =
* Dev - EAN-13 validation added.
* Dev - Backend - EAN input pattern now set to accept numbers only; max length set to 13.
= 1.0.0 - 30/12/2019 =
* Initial Release.
== Upgrade Notice ==
= 1.0.0 =
This is the first release of the plugin.