Plugin Directory

Changeset 2331656


Ignore:
Timestamp:
06/27/2020 01:25:40 PM (6 years ago)
Author:
escitsupport
Message:

v2.2 New development of the existing plugin

Location:
woo-product-shortcodes/trunk
Files:
15 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • woo-product-shortcodes/trunk/readme.txt

    r2213104 r2331656  
    55Requires at least: 4.3
    66Tested up to: 5.3.1
    7 Stable tag: 1.1
     7Stable tag: 2.2
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    27271. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly.
    28282. Activate the plugin through the 'Plugins' screen in WordPress
    29 3. On a page or post, add the shortcode to show product information. See below in FAQ for shortcode examples.
     293. Use our easy shortcode builder at TOOLS > WOO PRODUCT SHORTCODES
     304. On a page or post, add the shortcode to show product information. See below in FAQ for shortcode examples.
    3031
    3132
     
    8384== Changelog ==
    8485
     86= 2.2 =
     87* Minor changes post internal review
     88= 2.1 =
     89* Complete change to logic post WooCommerce upgrade
    8590= 1.1 =
    8691* Updates to images and tags
  • woo-product-shortcodes/trunk/woo-product-shortcodes.php

    r1705364 r2331656  
    11<?php
     2
    23/*
    3  Plugin Name: Woocommerce Product Shortcodes
    4  Plugin URI: http://www.escit.co.uk/wordpress/plugins/woo-product-shortcodes/
    5  Description: Add a product shortcode to show price, sku & more instead of using static text.
    6  Version: 1.1
    7  Author: ESC IT Support
    8  Author URI: http://www.escit.co.uk
    9  License: GPLv2 or later
    10  */
     4Plugin Name: Woo Product Shortcodes (Free)
     5Plugin URI: https://www.thewpmakers.com/woo-product-shortcodes-free/
     6Description: Let us look after your Wordpress Updates.
     7Version: 2.2
     8Author: The WP Makers
     9Author URI: https://www.thewpmakers.com
     10Text Domain: woo-product-shortcodes-free
     11*/
    1112
    12 if ( ! defined( 'ABSPATH' ) ) {
    13     exit; // Exit if accessed directly
     13if ( !function_exists( 'zfunction___woo_product_shortcode___menu' ) ) {
     14    function zfunction___woo_product_shortcode___menu() {
     15       add_management_page(
     16          'Woo Product Shortcodes',
     17          'Woo Product Shortcodes',
     18          'manage_options',
     19          'product_shortcodes_main___dashboard',
     20          'zfunction___woo_product_shortcodes___dashboard'
     21       );
     22       add_submenu_page(
     23          NULL,
     24          'Product Shortcodes: Settings',
     25          NULL,
     26          'manage_options',
     27          'product_shortcodes_main___settings',
     28          'zfunction___woo_product_shortcodes___settings'
     29       );
     30       add_submenu_page(
     31          NULL,
     32          'Product Shortcodes: Errors',
     33          NULL,
     34          'manage_options',
     35          'product_shortcodes_main___errors',
     36          'zfunction___woo_product_shortcodes___error_logs'
     37       );
     38    }
     39    add_action('admin_menu', 'zfunction___woo_product_shortcode___menu');
    1440}
    1541
    16 /**
    17  * Check if WooCommerce is active
    18  **/
     42
     43
     44if ( !function_exists( 'zfunction___woo_product_shortcode___register_setting___group' ) ) {
     45    function zfunction___woo_product_shortcode___register_setting___group() {
     46        register_setting('woo_product_shortcodes_group', 'woo_product_shortcodes___api_key' );
     47    }
     48    add_action( 'admin_init', 'zfunction___woo_product_shortcode___register_setting___group' );
     49}
     50
     51
     52if ( !function_exists( 'zfunction___woo_product_shortcodes___settings' ) ) {
     53    function zfunction___woo_product_shortcodes___settings() {
     54        $database_api_key = esc_attr(get_option('woo_product_shortcodes___api_key'));
     55        $default_tab = 'dashboard';
     56        $tab = isset($_GET['tab']) ? $_GET['tab'] : $default_tab;
     57        include('admin/page_header.php');
     58        include('admin/page_settings.php');
     59    }
     60}
     61
     62
     63
     64if ( !function_exists( 'zfunction___woo_product_shortcodes___dashboard' ) ) {
     65    function zfunction___woo_product_shortcodes___dashboard() {
     66        // logic
     67        //Get the active tab from the $_GET param
     68        $default_tab = 'dashboard';
     69        $tab = isset($_GET['tab']) ? $_GET['tab'] : $default_tab;
     70        include('admin/page_header.php');
     71
     72        include('admin/page_dashboard.php');
     73    }
     74}
     75
     76
     77
    1978if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    2079
    21     // https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html
     80    if ( !function_exists( 'zfunction___woo_product_shortcodes___shortcode_logic' ) ) {
    2281
    23     function function___woo_product_shortcodes( $woo_product_shortcode___atts ) {
    24        
    25         global $product;
    26            
    27         $woo_product_shortcode___atts = shortcode_atts( array(
    28                 'id'  =>  '',
    29                 'data_attribute'  =>  '',
    30             ), $woo_product_shortcode___atts );
    31      
    32         // If no id, we're probably on a product page already
    33         if ( !empty( $woo_product_shortcode___atts['id'] ) ) {
    34            
    35             //get which product from ID we should display a SKU for
    36             $woo_product_shortcode___product = wc_get_product( $woo_product_shortcode___atts['id'] );
     82      global $product;
    3783
    38             $woo_product_shortcode___product_name = $woo_product_shortcode___product->get_name();
    39             $woo_product_shortcode___product_get_short_description = $woo_product_shortcode___product->get_short_description();
    40             $woo_product_shortcode___product_sku = $woo_product_shortcode___product->get_sku();
    41             $woo_product_shortcode___product_get_price = $woo_product_shortcode___product->get_price();
    42             $woo_product_shortcode___product_get_regular_price = $woo_product_shortcode___product->get_regular_price();
    43             $woo_product_shortcode___product_get_sale_price = $woo_product_shortcode___product->get_sale_price();
     84      function zfunction___woo_product_shortcodes___shortcode_logic( $woo_product_shortcode___atts ) {
     85            $woo_product_shortcode___atts = shortcode_atts( array(
     86            'id'  =>  '',
     87            'data_attribute'  =>  '',
     88        ), $woo_product_shortcode___atts );
    4489
    45         }
     90        $woo_product_shortcode___atts___data_attribute = $woo_product_shortcode___atts['data_attribute'];
     91        if ( !empty( $woo_product_shortcode___atts['id'] ) ) {
    4692
    47         ob_start();
    48        
    49         // logic to determine what text to return
    50         if ( $woo_product_shortcode___atts['data_attribute'] == 'name' ) {
    51             echo $woo_product_shortcode___product_name;
    52         }
    53         elseif ( $woo_product_shortcode___atts['data_attribute'] == 'short_description' ) {
    54             echo $woo_product_shortcode___product_get_short_description;
    55         }
    56         elseif ( $woo_product_shortcode___atts['data_attribute'] == 'sku' ) {
    57             echo $woo_product_shortcode___product_sku;
    58         }
    59         elseif ( $woo_product_shortcode___atts['data_attribute'] == 'price' ) {
    60             echo $woo_product_shortcode___product_get_price;
    61         }
    62         elseif ( $woo_product_shortcode___atts['data_attribute'] == 'regular_price' ) {
    63             echo $woo_product_shortcode___product_get_regular_price;
    64         }
    65         elseif ( $woo_product_shortcode___atts['data_attribute'] == 'sale_price' ) {
    66             echo $woo_product_shortcode___product_get_sale_price;
    67         }
    68         elseif ( isset($woo_product_shortcode___atts['data_attribute']) ) {
    69             echo 'ERR002: Invalid data_attribute defined.';
    70         }       
    71         else {
    72             echo 'ERR001: No valid attribute defined.';
    73         }
    74        
    75         return ob_get_clean();
    76        
    77     }
    78     add_shortcode( 'woo-product-shortcodes', 'function___woo_product_shortcodes' );
     93          // get product info
     94          $var___get_post_type = get_post_type($woo_product_shortcode___atts['id']);
     95          if($var___get_post_type == 'product'){
     96            $var___wc_get_product = wc_get_product($woo_product_shortcode___atts['id']);
     97            $var___wc_get_product___price = $var___wc_get_product->get_price();
     98            $var___wc_get_product___sku = $var___wc_get_product->get_sku();
     99            $var___wc_get_product___name = $var___wc_get_product->get_name();
     100                $var___wc_get_product___description = $var___wc_get_product->get_short_description();
     101                $var___wc_get_product___reg_price = $var___wc_get_product->get_regular_price();
     102                $var___wc_get_product___sale_price = $var___wc_get_product->get_sale_price();
     103            // PREMIUM_START
     104            // PREMIUM_END
    79105
     106            // data to be returned
     107            // FREE
     108            if ( $woo_product_shortcode___atts___data_attribute == 'price' ) {
     109              $var___output = $var___wc_get_product___price;
     110            }elseif ( $woo_product_shortcode___atts___data_attribute == 'name' ) {
     111              $var___output = $var___wc_get_product___name;
     112            }elseif ( $woo_product_shortcode___atts___data_attribute == 'short_description' ) {
     113              $var___output = $var___wc_get_product___description;
     114            } elseif ( $woo_product_shortcode___atts___data_attribute == 'sku' ) {
     115            $var___output = $var___wc_get_product___sku;
     116            }elseif ( $woo_product_shortcode___atts___data_attribute == 'regular_price' ) {
     117              $var___output = $var___wc_get_product___reg_price;
     118            }elseif ( $woo_product_shortcode___atts___data_attribute == 'sale_price' ) {
     119              $var___output = $var___wc_get_product___sale_price;
     120            // PREMIUM_START
     121            // PREMIUM_END
     122
     123            } else {
     124              $var___output = 'ERROR101: Invalid Data Attribute sent';
     125            }
     126          } elseif(empty($var___get_post_type)) {
     127            $var___output = 'ERROR103: Invalid ID sent.';
     128          }else {
     129            $var___output = 'ERROR104: Invalid ID sent. Expecting a product but received ' . $var___get_post_type;
     130          }
     131        } else {
     132          $var___output = 'ERROR102: No Product ID sent';
     133        }
     134        return $var___output;
     135      }
     136
     137        add_shortcode( 'woo-product-shortcodes', 'zfunction___woo_product_shortcodes___shortcode_logic' );
     138
     139    }
    80140}
     141
     142?>
Note: See TracChangeset for help on using the changeset viewer.