Changeset 2331656
- Timestamp:
- 06/27/2020 01:25:40 PM (6 years ago)
- Location:
- woo-product-shortcodes/trunk
- Files:
-
- 15 added
- 1 deleted
- 2 edited
-
admin (added)
-
admin/css (added)
-
admin/images (added)
-
admin/js (added)
-
admin/page_dashboard.php (added)
-
admin/page_error_logs.php (added)
-
admin/page_header.php (added)
-
admin/page_settings.php (added)
-
includes (added)
-
index.php (deleted)
-
languages (added)
-
public (added)
-
public/css (added)
-
public/images (added)
-
public/js (added)
-
readme.txt (modified) (3 diffs)
-
uninstall.php (added)
-
woo-product-shortcodes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
woo-product-shortcodes/trunk/readme.txt
r2213104 r2331656 5 5 Requires at least: 4.3 6 6 Tested up to: 5.3.1 7 Stable tag: 1.17 Stable tag: 2.2 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 27 27 1. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly. 28 28 2. 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. 29 3. Use our easy shortcode builder at TOOLS > WOO PRODUCT SHORTCODES 30 4. On a page or post, add the shortcode to show product information. See below in FAQ for shortcode examples. 30 31 31 32 … … 83 84 == Changelog == 84 85 86 = 2.2 = 87 * Minor changes post internal review 88 = 2.1 = 89 * Complete change to logic post WooCommerce upgrade 85 90 = 1.1 = 86 91 * Updates to images and tags -
woo-product-shortcodes/trunk/woo-product-shortcodes.php
r1705364 r2331656 1 1 <?php 2 2 3 /* 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 */4 Plugin Name: Woo Product Shortcodes (Free) 5 Plugin URI: https://www.thewpmakers.com/woo-product-shortcodes-free/ 6 Description: Let us look after your Wordpress Updates. 7 Version: 2.2 8 Author: The WP Makers 9 Author URI: https://www.thewpmakers.com 10 Text Domain: woo-product-shortcodes-free 11 */ 11 12 12 if ( ! defined( 'ABSPATH' ) ) { 13 exit; // Exit if accessed directly 13 if ( !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'); 14 40 } 15 41 16 /** 17 * Check if WooCommerce is active 18 **/ 42 43 44 if ( !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 52 if ( !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 64 if ( !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 19 78 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 20 79 21 // https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html 80 if ( !function_exists( 'zfunction___woo_product_shortcodes___shortcode_logic' ) ) { 22 81 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; 37 83 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 ); 44 89 45 } 90 $woo_product_shortcode___atts___data_attribute = $woo_product_shortcode___atts['data_attribute']; 91 if ( !empty( $woo_product_shortcode___atts['id'] ) ) { 46 92 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 79 105 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 } 80 140 } 141 142 ?>
Note: See TracChangeset
for help on using the changeset viewer.