Plugin Directory

Changeset 2406268


Ignore:
Timestamp:
10/25/2020 03:23:57 PM (5 years ago)
Author:
kreamweb
Message:

version 1.1.0

Location:
product-gtin-ean-upc-isbn-for-woocommerce
Files:
18 added
2 edited

Legend:

Unmodified
Added
Removed
  • product-gtin-ean-upc-isbn-for-woocommerce/trunk/product-gtin-ean-upc-isbn-for-woocommerce.php

    r2291765 r2406268  
    11<?php
     2
    23/**
    34 * Plugin Name: Product GTIN (EAN, UPC, ISBN) for WooCommerce
    45 * Author URI: https://emanuelacastorina.com/
    56 * Description: Add a Global Trade Item Number (EAN, UPC, ISBN, JAN, ITF-14) field to WooCommerce
    6  * Version: 1.0.9
     7 * Version: 1.1.0
    78 * Author: Emanuela Castorina
    89 * Text Domain: product-gtin-ean-upc-isbn-for-woocommerce
    910 * Domain Path: /languages
    10  * WC tested up to: 4.1
     11 * WC tested up to: 4.7
    1112 * WC requires at least: 3.0
    1213 */
    1314
    1415
    15 if ( ! defined( 'ABSPATH' ) ) {
     16if (!defined('ABSPATH')) {
    1617    exit; // Exit if accessed directly
    1718}
     
    2021 * Currently plugin version.
    2122 */
    22 if ( ! defined( 'WPM_PRODUCT_GTIN_WC_VERSION' ) ) {
    23     define( 'WPM_PRODUCT_GTIN_WC_VERSION', '1.0.9' );
     23if (!defined('WPM_PRODUCT_GTIN_WC_VERSION')) {
     24    define('WPM_PRODUCT_GTIN_WC_VERSION', '1.1.0');
    2425}
    2526
    2627// Define WPM_PRODUCT_GTIN_WC_FILE.
    27 if ( ! defined( 'WPM_PRODUCT_GTIN_WC_FILE' ) ) {
    28     define( 'WPM_PRODUCT_GTIN_WC_FILE', __FILE__ );
     28if (!defined('WPM_PRODUCT_GTIN_WC_FILE')) {
     29    define('WPM_PRODUCT_GTIN_WC_FILE', __FILE__);
    2930}
    3031
    3132// Define WPM_PRODUCT_GTIN_WC_DIR.
    32 if ( ! defined( 'WPM_PRODUCT_GTIN_WC_DIR' ) ) {
    33     define( 'WPM_PRODUCT_GTIN_WC_DIR', plugin_dir_path( __FILE__ )  );
     33if (!defined('WPM_PRODUCT_GTIN_WC_DIR')) {
     34    define('WPM_PRODUCT_GTIN_WC_DIR', plugin_dir_path(__FILE__));
    3435}
    3536
    3637// Define WPM_PRODUCT_GTIN_WC_URL.
    37 if ( ! defined( 'WPM_PRODUCT_GTIN_WC_URL' ) ) {
    38     define( 'WPM_PRODUCT_GTIN_WC_URL', plugins_url( '/', __FILE__ ) );
     38if (!defined('WPM_PRODUCT_GTIN_WC_URL')) {
     39    define('WPM_PRODUCT_GTIN_WC_URL', plugins_url('/', __FILE__));
    3940}
    4041
    4142// Define WPM_PRODUCT_GTIN_WC_ASSETS_URL.
    42 if ( ! defined( 'WPM_PRODUCT_GTIN_WC_ASSETS_URL' ) ) {
    43     define( 'WPM_PRODUCT_GTIN_WC_ASSETS_URL', WPM_PRODUCT_GTIN_WC_URL . 'assets' );
     43if (!defined('WPM_PRODUCT_GTIN_WC_ASSETS_URL')) {
     44    define('WPM_PRODUCT_GTIN_WC_ASSETS_URL', WPM_PRODUCT_GTIN_WC_URL . 'assets');
    4445}
    4546
    4647// Include the main class.
    47 if ( ! class_exists( 'WPM_Product_GTIN_WC' ) ) {
    48     include_once dirname( __FILE__ ) . '/includes/class.product-gtin-wc.php';
     48if (!class_exists('WPM_Product_GTIN_WC')) {
     49    include_once dirname(__FILE__) . '/includes/class.product-gtin-wc.php';
    4950}
    5051/**
     
    5354 * @return WPM_Product_GTIN_WC
    5455 */
    55 if ( ! function_exists( 'wpm_product_gtin_wc' ) ) {
     56if (!function_exists('wpm_product_gtin_wc')) {
    5657
    5758    /**
     
    6061     * @return WPM_Free_Gift_Coupons
    6162     */
    62     function wpm_product_gtin_wc() {
     63    function wpm_product_gtin_wc()
     64    {
    6365        return WPM_Product_GTIN_WC::instance();
    6466    }
     
    6668    $GLOBALS['wpm_product_gtin_wc'] = wpm_product_gtin_wc();
    6769}
     70
     71
     72/**
     73 * Return instance of WPM_Product_GTIN_WC.
     74 *
     75 * @return WPM_Product_GTIN_WC
     76 */
     77if (!function_exists('wpm_get_code_gtin_by_product')) {
     78
     79    /**
     80     * Return the code of the product.
     81     *
     82     * @return string
     83     */
     84    function wpm_get_code_gtin_by_product($product)
     85    {
     86        if (is_numeric($product)) {
     87            $product = wc_get_product($product);
     88        }
     89
     90        if ($product instanceof WC_Product) {
     91            $code = $product->get_meta('_wpm_gtin_code');
     92            $parent_id = $product->get_parent_id();
     93            if (empty($code) && $parent_id) {
     94                return wpm_get_code_gtin_by_product($parent_id);
     95            } else {
     96                return $code;
     97            }
     98        }
     99
     100        return '';
     101    }
     102}
  • product-gtin-ean-upc-isbn-for-woocommerce/trunk/readme.txt

    r2291767 r2406268  
    66Requires at least: 4.0.0
    77Requires PHP: 7.0
    8 Tested up to: 5.4
    9 Stable tag: 1.0.9
     8Tested up to: 5.5
     9Stable tag: 1.1.0
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6666If your product is variable, you can set a GTIN code for each variation; you can fill out the GTIN field that you'll find inside the variation detail panel.
    6767
     68= How can I get a GTIN code for a product? =
     69
     70Since version 1.1.0 it is possible use the function wpm_get_code_gtin_by_product that need the product id or the product object.
     71The function returns the GTIN code as string.
     72
     73`$gtin = wpm_get_code_gtin_by_product($product_id);`
     74
    6875= Where is stored the GTIN code ? =
    6976The GTIN code is a private custom field of product with *meta_key* `_wpm_gtin_code`
     
    114121
    115122== Changelog ==
     123= 1.1.0 - Released: 25 Oct, 2020 =
     124*  New: Support for WordPress 5.5
     125*  New: Support for WooCommerce 4.7
     126*  Dev: New function wpm_get_code_gtin_by_product to get the GTIN code by product id or product
     127
    116128= 1.0.9 - Released: 25 April, 2020 =
    117129*  New: Support for WooCommerce 4.1
Note: See TracChangeset for help on using the changeset viewer.