├── .gitignore ├── README.md ├── index.php ├── languages └── woocommerce-dynamic-pricing-table.pot ├── readme.txt └── woocommerce-dynamic-pricing-table.php /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X metadata 2 | .DS_Store 3 | 4 | # Windows junk 5 | Thumbs.db 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WooCommerce Dynamic Pricing Table 2 | 3 | This extension will add a pricing table and other discount notifications for customers on the frontend of your WooCommerce store when using the [WooCommerce Dynamic Pricing](https://www.woocommerce.com/products/dynamic-pricing/) plugin. 4 | 5 | ## Advanced Product Discount Table 6 | 7 | **Note:** The extension does not provide styling for the [Advanced Product Discount](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-7) table and any table styling must be provided by your theme itself or by CSS you write. The screenshot below is taken from the [WooCommerce Storefront Theme](https://www.woocommerce.com/storefront/) which does have table styling on product pages included within the theme. 8 | 9 | ![mixed percentage and fixed dynamic pricing woodev](https://cloud.githubusercontent.com/assets/1190565/17950726/ea7dff32-6a54-11e6-92f5-e1ca36c4868f.png) 10 | 11 | ## User Role Discount Messages 12 | 13 | [User Role](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-2) discount notification messages are displayed on the WooCommerce product sections. 14 | 15 | ![products woodev](https://cloud.githubusercontent.com/assets/1190565/18025016/3e0735be-6c13-11e6-974b-687ffb3fa7ce.png) 16 | 17 | ## Simple Category Discount Messages 18 | 19 | [Simple Category Pricing](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-4) discount notification messages are displayed on the on WooCommerce product category sections. 20 | 21 | ![simple-category-discount](https://cloud.githubusercontent.com/assets/1190565/18104005/05035e2e-6ef1-11e6-8364-088994355b89.png) 22 | 23 | ## Installation 24 | 25 | 1. Download the plugin from it's GitHub Repository Download [WooCommerce Dynamic Pricing Table](https://github.com/stuartduff/woocommerce-dynamic-pricing-table). 26 | 2. Goto WordPress > Appearance > Plugins > Add New. 27 | 3. Click Upload Plugin and Choose File, then select the plugin's .zip file. Click Install Now. 28 | 4. Click Activate to use your new plugin right away. 29 | 30 | ## Minimum Requirements 31 | 32 | For this extension to function [WooCommerce](https://www.woocommerce.com/) and the [WooCommerce Dynamic Pricing](https://www.woocommerce.com/products/dynamic-pricing/) extension must be installed and activated on your [WordPress](https://wordpress.org/) site. 33 | 34 | ## FAQ 35 | 36 | > What type of discounts does the extension display. 37 | 38 | * [Advanced Product Discounts](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-7) on WooCommerce products that have either a bulk or special offer discount applied to them. 39 | * [User Role Discount](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-2) will display on WooCommerce product sections. 40 | * [Simple Category Pricing](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-4) will display category discounts on WooCommrce product categories. 41 | 42 | > Are there any limitations to how many product tables will display on an single product. 43 | 44 | Only one advanced product pricing group table will display on any single product, if you have more than one pricing group active on a single product the discount table will then be disabled. 45 | 46 | > Where should I contact if I have an issue with this extension. 47 | 48 | All support requests for this extension should be posted to the [WooCommerce Dynamic Pricing Table Issue Tracker ](https://github.com/stuartduff/woocommerce-dynamic-pricing-table/issues) here on Github. 49 | 50 | ## Changelog 51 | 52 | **1.0.6 - 19/02/20** 53 | * Fix - Various small fixes to stop error messages from displaying in WooCommerce v3.9+ 54 | 55 | **1.0.5 - 05/09/16** 56 | * Fix - Added check to prevent wc_add_notice() from trying to display on admin. 57 | 58 | **1.0.4 - 30/08/16** 59 | * Feature - Added the ability to display [Simple Category Pricing](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-4) discounts on WooCommerce categories. 60 | 61 | **1.0.3 - 27/08/16** 62 | * Feature - Added the ability to display [User Role Pricing](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-2) discounts on WooCommerce sections. 63 | 64 | **1.0.2 - 26/08/16** 65 | * Fix - Changed the quantity number output to use the WooCommerce [wc_stock_amount()](https://docs.woocommerce.com/wc-apidocs/function-wc_stock_amount.html) function. 66 | 67 | **1.0.1 - 25/08/16** 68 | * Fix - Changed the monetary number output to use the WooCommerce [wc_price()](https://docs.woocommerce.com/wc-apidocs/function-wc_price.html) function. 69 | * Fix - If the max quantity field of a product pricing group is less than 1 or left blank "or more" text will now display instead of a 0. 70 | 71 | **1.0.0 - 20/06/16** 72 | * Initial Release - first version of the plugin released. 73 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | \n" 9 | "Language-Team: \n" 10 | "Language: \n" 11 | "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION\n" 12 | "MIME-Version: 1.0\n" 13 | "Content-Type: text/plain; charset=UTF-8\n" 14 | "Content-Transfer-Encoding: 8bit\n" 15 | "X-Generator: Loco - https://localise.biz/" 16 | 17 | #: woocommerce-dynamic-pricing-table.php:156 18 | msgid "" 19 | "The WooCommerce Dynamic Pricing Table extension requires that you have the " 20 | "WooCommerce Dynamic Pricing plugin installed and activated." 21 | msgstr "" 22 | 23 | #: woocommerce-dynamic-pricing-table.php:156 24 | msgid "Get WooCommerce Dynamic Pricing now" 25 | msgstr "" 26 | 27 | #: woocommerce-dynamic-pricing-table.php:202 28 | #: woocommerce-dynamic-pricing-table.php:259 29 | msgid "Quantity" 30 | msgstr "" 31 | 32 | #: woocommerce-dynamic-pricing-table.php:202 33 | msgid "Bulk Purchase Pricing" 34 | msgstr "" 35 | 36 | #: woocommerce-dynamic-pricing-table.php:210 37 | msgid " or more" 38 | msgstr "" 39 | 40 | #: woocommerce-dynamic-pricing-table.php:222 41 | #: woocommerce-dynamic-pricing-table.php:272 42 | msgid "%1$s Discount Per Item" 43 | msgstr "" 44 | 45 | #: woocommerce-dynamic-pricing-table.php:226 46 | #: woocommerce-dynamic-pricing-table.php:276 47 | msgid "% Discount" 48 | msgstr "" 49 | 50 | #: woocommerce-dynamic-pricing-table.php:230 51 | #: woocommerce-dynamic-pricing-table.php:280 52 | msgid "%1$s Per Item" 53 | msgstr "" 54 | 55 | #: woocommerce-dynamic-pricing-table.php:259 56 | msgid "Special Offer Pricing" 57 | msgstr "" 58 | 59 | #: woocommerce-dynamic-pricing-table.php:267 60 | msgid "Buy %1$s get %2$s more discounted" 61 | msgstr "" 62 | 63 | #: woocommerce-dynamic-pricing-table.php:340 64 | msgid "" 65 | "Hi %1$s as a %2$s you will receive a %3$s percent discount on all products." 66 | msgstr "" 67 | 68 | #: woocommerce-dynamic-pricing-table.php:344 69 | msgid "Hi %1$s as a %2$s you will receive a %3$s discount on all products." 70 | msgstr "" 71 | 72 | #: woocommerce-dynamic-pricing-table.php:390 73 | msgid "" 74 | "You will receive a %1$s percent discount on all products within the %2$s " 75 | "category." 76 | msgstr "" 77 | 78 | #: woocommerce-dynamic-pricing-table.php:394 79 | msgid "" 80 | "You will receive %1$s discount on all products within the %2$s category." 81 | msgstr "" 82 | 83 | #. Name of the plugin 84 | msgid "WooCommerce Dynamic Pricing Table" 85 | msgstr "" 86 | 87 | #. Description of the plugin 88 | msgid "" 89 | "Adds a pricing discount table to WooCommerce products that are offering bulk " 90 | "discounts or special offer discounts via the WooCommerce Dynamic Pricing " 91 | "plugin." 92 | msgstr "" 93 | 94 | #. URI of the plugin 95 | msgid "https://github.com/stuartduff/woocommerce-dynamic-pricing-table" 96 | msgstr "" 97 | 98 | #. Author of the plugin 99 | msgid "Stuart Duff" 100 | msgstr "" 101 | 102 | #. Author URI of the plugin 103 | msgid "http://stuartduff.com" 104 | msgstr "" 105 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === WooCommerce Dynamic Pricing Table === 2 | Contributors: stuartduff 3 | Tags: ecommerce, e-commerce, store, sales, sell, shop, cart, checkout, storefront 4 | Requires at least: 4.5 5 | Tested up to: 4.5.2 6 | Stable tag: 1.0.5 7 | License: GPLv3 8 | License URI: https://www.gnu.org/licenses/gpl-3.0.html 9 | 10 | == Description == 11 | 12 | This extension will add a pricing table and other discount notifications for customers on the frontend of your WooCommerce store when using the [WooCommerce Dynamic Pricing](https://www.woocommerce.com/products/dynamic-pricing/) plugin. 13 | == Installation == 14 | 15 | 1. Download the plugin from it's GitHub Repository Download [WooCommerce Dynamic Pricing Table](https://github.com/stuartduff/woocommerce-dynamic-pricing-table). 16 | 2. Goto WordPress > Appearance > Plugins > Add New. 17 | 3. Click Upload Plugin and Choose File, then select the plugin's .zip file. Click Install Now. 18 | 4. Click Activate to use your new plugin right away. 19 | 20 | == Minimum Requirements == 21 | 22 | For this extension to function [WooCommerce](https://www.woocommerce.com/) and the [WooCommerce Dynamic Pricing](https://www.woocommerce.com/products/dynamic-pricing/) extension must be installed and activated on your WordPress site. 23 | 24 | = FAQ = 25 | 26 | Below are the discounts that the plugin will currently display. 27 | 28 | * [Advanced Product Discounts](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-7) on WooCommerce products that have either a bulk or special offer discount applied to them. 29 | * [User Role Discount](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-2) will display on WooCommerce product sections. 30 | * [Simple Category Pricing](https://docs.woocommerce.com/document/woocommerce-dynamic-pricing/#section-4) will display category discounts on WooCommrce product categories. 31 | 32 | == Changelog == 33 | 34 | = 1.0.6 - 19/02/20 = 35 | * Fix - Various small fixes to stop error messages from displaying in WooCommerce v3.9+ 36 | 37 | = 1.0.5 - 05/09/16 = 38 | * Fix - Added check to prevent wc_add_notice() from trying to display on admin. 39 | 40 | = 1.0.4 - 30/08/16 = 41 | * Feature - Added the ability to display Simple Category Pricing discounts on WooCommerce categories. 42 | 43 | = 1.0.3 - 27/08/16 = 44 | * Feature - Added the ability to display User Role Pricing discounts on WooCommerce sections. 45 | 46 | = 1.0.2 - 26/08/16 = 47 | * Fix - Changed the quantity number output to use the WooCommerce [wc_stock_amount()](https://docs.woocommerce.com/wc-apidocs/function-wc_stock_amount.html) function. 48 | 49 | = 1.0.1 - 25/08/16 = 50 | * Fix - Changed the monetary number output to use the WooCommerce wc_price() function. 51 | * Fix - If the max quantity field of a product pricing group is less than 1 or left blank "or more" text will now display instead of a 0. 52 | 53 | = 1.0.0 - 20/06/16 = 54 | * Initial Release - first version of the plugin released. 55 | -------------------------------------------------------------------------------- /woocommerce-dynamic-pricing-table.php: -------------------------------------------------------------------------------- 1 | token = 'woocommerce-dynamic-pricing-table'; 75 | $this->plugin_url = plugin_dir_url( __FILE__ ); 76 | $this->plugin_path = plugin_dir_path( __FILE__ ); 77 | $this->version = '1.0.0'; 78 | 79 | register_activation_hook( __FILE__, array( $this, 'install' ) ); 80 | 81 | add_action( 'init', array( $this, 'load_plugin_textdomain' ) ); 82 | 83 | add_action( 'init', array( $this, 'plugin_setup' ) ); 84 | 85 | } 86 | 87 | /** 88 | * Main WC_Dynamic_Pricing_Table Instance 89 | * 90 | * Ensures only one instance of WC_Dynamic_Pricing_Table is loaded or can be loaded. 91 | * 92 | * @since 1.0.0 93 | * @static 94 | * @see WC_Dynamic_Pricing_Table() 95 | * @return Main WC_Dynamic_Pricing_Table instance 96 | */ 97 | public static function instance() { 98 | if ( is_null( self::$_instance ) ) 99 | self::$_instance = new self(); 100 | return self::$_instance; 101 | } // End instance() 102 | 103 | /** 104 | * Load the localisation file. 105 | * @access public 106 | * @since 1.0.0 107 | * @return void 108 | */ 109 | public function load_plugin_textdomain() { 110 | load_plugin_textdomain( 'woocommerce-dynamic-pricing-table', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 111 | } 112 | 113 | /** 114 | * Installation. 115 | * Runs on activation. Logs the version number. 116 | * @access public 117 | * @since 1.0.0 118 | * @return void 119 | */ 120 | public function install() { 121 | $this->log_plugin_version_number(); 122 | } 123 | 124 | /** 125 | * Log the plugin version number. 126 | * @access private 127 | * @since 1.0.0 128 | * @return void 129 | */ 130 | private function log_plugin_version_number() { 131 | // Log the version number. 132 | update_option( $this->token . '-version', $this->version ); 133 | } 134 | 135 | /** 136 | * Setup all the things. 137 | * Only executes if WooCommerce Dynamic Pricing is active. 138 | * If WooCommerce Dynamic Pricing is inactive an admin notice is displayed. 139 | * @return void 140 | */ 141 | public function plugin_setup() { 142 | if ( class_exists( 'WC_Dynamic_Pricing' ) ) { 143 | add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'output_dynamic_pricing_table' ) ); 144 | 145 | if ( ! is_admin() ) { 146 | add_action( 'wp', array( $this, 'output_dynamic_pricing_role_message' ) ); 147 | add_action( 'wp', array( $this, 'output_dynamic_pricing_category_message' ) ); 148 | } 149 | } else { 150 | add_action( 'admin_notices', array( $this, 'install_wc_dynamic_pricing_notice' ) ); 151 | } 152 | } 153 | 154 | /** 155 | * WooCommerce Dynamic Pricing plugin install notice. 156 | * If the user activates this plugin while not having the WooCommerce Dynamic Pricing plugin installed or activated, prompt them to install WooCommerce Dynamic Pricing. 157 | * @since 1.0.0 158 | * @return void 159 | */ 160 | public function install_wc_dynamic_pricing_notice() { 161 | echo '
162 |

' . __( 'The WooCommerce Dynamic Pricing Table extension requires that you have the WooCommerce Dynamic Pricing plugin installed and activated.', 'woocommerce-dynamic-pricing-table' ) . ' ' . __( 'Get WooCommerce Dynamic Pricing now', 'woocommerce-dynamic-pricing-table' ) . '

163 |
'; 164 | } 165 | 166 | /** 167 | * Gets the dynamic pricing rules sets from the post meta. 168 | * @access public 169 | * @since 1.0.0 170 | * @return get_post_meta() 171 | */ 172 | public function get_pricing_array_rule_sets() { 173 | return get_post_meta( get_the_ID(), '_pricing_rules', true ); 174 | } 175 | 176 | /** 177 | * Gets the current user. 178 | * @access public 179 | * @since 1.0.0 180 | * @return wp_get_current_user() 181 | */ 182 | public function get_current_user() { 183 | return wp_get_current_user(); 184 | } 185 | 186 | /** 187 | * Gets the current category. 188 | * @access public 189 | * @since 1.0.0 190 | * @return get_queiried object() 191 | */ 192 | public function pricing_queried_object() { 193 | return get_queried_object(); 194 | } 195 | 196 | /** 197 | * Outputs the dynamic bulk pricing table. 198 | * @access public 199 | * @since 1.0.0 200 | * @return $output 201 | */ 202 | public function bulk_pricing_table_output() { 203 | 204 | $array_rule_sets = $this->get_pricing_array_rule_sets(); 205 | 206 | $output = ''; 207 | 208 | $output .= ''; 209 | 210 | foreach( $array_rule_sets as $pricing_rule_sets ) { 211 | 212 | foreach ( $pricing_rule_sets['rules'] as $key => $value ) { 213 | 214 | // Checks if a product discount group max quantity field is less than 1. 215 | if ( $pricing_rule_sets['rules'][$key]['to'] < 1 ){ 216 | $rules_to = __( ' or more', 'woocommerce-dynamic-pricing-table' ); 217 | } else { 218 | $rules_to = ' - ' . wc_stock_amount( $pricing_rule_sets['rules'][$key]['to'] ); 219 | } 220 | 221 | $output .= ''; 222 | 223 | $output .= ''; 224 | 225 | switch ( $pricing_rule_sets['rules'][$key]['type'] ) { 226 | 227 | case 'price_discount': 228 | $output .= ''; 229 | break; 230 | 231 | case 'percentage_discount': 232 | $output .= ''; 233 | break; 234 | 235 | case 'fixed_price': 236 | $output .= ''; 237 | break; 238 | 239 | } 240 | 241 | $output .= ''; 242 | 243 | } 244 | 245 | } 246 | 247 | $output .= '
' . __( 'Quantity' , 'woocommerce-dynamic-pricing-table' ) . '' . __( 'Bulk Purchase Pricing' , 'woocommerce-dynamic-pricing-table' ) . '
' . wc_stock_amount( $pricing_rule_sets['rules'][$key]['from'] ) . $rules_to . '' . sprintf( __( '%1$s Discount Per Item', 'woocommerce-dynamic-pricing-table' ), wc_price( $pricing_rule_sets['rules'][$key]['amount'] ) ) . '' . floatval( $pricing_rule_sets['rules'][$key]['amount'] ) . __( '% Discount', 'woocommerce-dynamic-pricing-table' ) . '' . sprintf( __( '%1$s Per Item', 'woocommerce-dynamic-pricing-table' ), wc_price( $pricing_rule_sets['rules'][$key]['amount'] ) ) . '
'; 248 | 249 | echo $output; 250 | 251 | } 252 | 253 | /** 254 | * Outputs the dynamic special offer pricing table. 255 | * @access public 256 | * @since 1.0.0 257 | * @return $output 258 | */ 259 | public function special_offer_pricing_table_output() { 260 | 261 | $array_rule_sets = $this->get_pricing_array_rule_sets(); 262 | 263 | $output = ''; 264 | 265 | $output .= ''; 266 | 267 | foreach( $array_rule_sets as $pricing_rule_sets ) { 268 | 269 | foreach ( $pricing_rule_sets['blockrules'] as $key => $value ) { 270 | 271 | $output .= ''; 272 | 273 | $output .= ''; 274 | 275 | switch ( $pricing_rule_sets['blockrules'][$key]['type'] ) { 276 | 277 | case 'fixed_adjustment': 278 | $output .= ''; 279 | break; 280 | 281 | case 'percent_adjustment': 282 | $output .= ''; 283 | break; 284 | 285 | case 'fixed_price': 286 | $output .= ''; 287 | break; 288 | 289 | } 290 | 291 | $output .= ''; 292 | 293 | } 294 | 295 | } 296 | 297 | $output .= '
' . __( 'Quantity', 'woocommerce-dynamic-pricing-table' ) . '' . __( 'Special Offer Pricing', 'woocommerce-dynamic-pricing-table' ) . '
' . sprintf( __( 'Buy %1$s get %2$s more discounted', 'woocommerce-dynamic-pricing-table' ), wc_stock_amount( $pricing_rule_sets['blockrules'][$key]['from'] ), wc_stock_amount( $pricing_rule_sets['blockrules'][$key]['adjust'] ) ) . '' . sprintf( __( '%1$s Discount Per Item', 'woocommerce-dynamic-pricing-table' ), wc_price( $pricing_rule_sets['blockrules'][$key]['amount'] ) ) . '' . floatval( $pricing_rule_sets['blockrules'][$key]['amount'] ) . __( '% Discount', 'woocommerce-dynamic-pricing-table' ) . '' . sprintf( __( '%1$s Per Item', 'woocommerce-dynamic-pricing-table' ), wc_price( $pricing_rule_sets['blockrules'][$key]['amount'] ) ) . '
'; 298 | 299 | echo $output; 300 | 301 | } 302 | 303 | /** 304 | * Outputs the dynamic pricing table. 305 | * @access public 306 | * @since 1.0.0 307 | */ 308 | public function output_dynamic_pricing_table() { 309 | 310 | $array_rule_sets = $this->get_pricing_array_rule_sets(); 311 | 312 | if ( $array_rule_sets && is_array( $array_rule_sets ) && sizeof( $array_rule_sets ) == 1 ) { 313 | foreach( $array_rule_sets as $pricing_rule_sets ) { 314 | if ( $pricing_rule_sets['mode'] == 'continuous' ) : 315 | $this->bulk_pricing_table_output(); 316 | elseif ( $pricing_rule_sets['mode'] == 'block' ) : 317 | $this->special_offer_pricing_table_output(); 318 | endif; 319 | } 320 | } 321 | } 322 | 323 | /** 324 | * The role discount notification message. 325 | * @access public 326 | * @since 1.0.0 327 | * @return wc_add_notice() 328 | */ 329 | public function role_discount_notification_message() { 330 | 331 | $role_pricing_rule_sets = get_option( '_s_membership_pricing_rules', array() ); 332 | $current_user_role = $this->get_current_user()->roles[0]; 333 | $current_user_display_name = $this->get_current_user()->display_name; 334 | 335 | foreach( $role_pricing_rule_sets as $role_rules ) { 336 | 337 | // Gets the discount role of the user and the discount amount. 338 | $user_discount_role = isset( $role_rules['conditions'][0]['args']['roles'][0] ) ? $role_rules['conditions'][0]['args']['roles'][0] : ''; 339 | $role_discount_amount = $role_rules['rules'][0]['amount']; 340 | 341 | if ( is_woocommerce() && $current_user_role === $user_discount_role && null !== $user_discount_role ) { 342 | 343 | switch ( $role_rules['rules'][0]['type'] ) { 344 | 345 | case 'percent_product': 346 | $info_message = sprintf( __( 'Hi %1$s as a %2$s you will receive a %3$s percent discount on all products.', 'woocommerce-dynamic-pricing-table' ), esc_attr( $current_user_display_name ), esc_attr( $current_user_role ), floatval( $role_discount_amount ) ); 347 | break; 348 | 349 | case 'fixed_product': 350 | $info_message = sprintf( __( 'Hi %1$s as a %2$s you will receive a %3$s discount on all products.', 'woocommerce-dynamic-pricing-table' ), esc_attr( $current_user_display_name ), esc_attr( $current_user_role ), wc_price( $role_discount_amount ) ); 351 | break; 352 | 353 | } 354 | 355 | // Output role discount message 356 | wc_add_notice( $info_message, 'notice' ); 357 | 358 | } 359 | 360 | } 361 | 362 | } 363 | 364 | /** 365 | * Outputs the role notificaton message. 366 | * @access public 367 | * @since 1.0.0 368 | */ 369 | public function output_dynamic_pricing_role_message() { 370 | $this->role_discount_notification_message(); 371 | } 372 | 373 | /** 374 | * The category discount notification message. 375 | * @access public 376 | * @since 1.0.0 377 | * @return wc_add_notice() 378 | */ 379 | public function category_discount_notification_message() { 380 | 381 | $category_pricing_rule_sets = get_option( '_s_category_pricing_rules', array() ); 382 | $current_product_category = $this->pricing_queried_object()->term_id; 383 | $current_category_name = $this->pricing_queried_object()->name; 384 | 385 | foreach( $category_pricing_rule_sets as $category_rules ) { 386 | 387 | // Gets the discount category and the discount amount set for the category. 388 | $discount_category = isset( $category_rules['collector']['args']['cats'][0] ) ? $category_rules['collector']['args']['cats'][0] : ''; 389 | $category_discount_amount = $category_rules['rules'][0]['amount']; 390 | 391 | 392 | if ( is_product_category() && $current_product_category == $discount_category && null != $discount_category ) { 393 | 394 | switch ( $category_rules['rules'][0]['type'] ) { 395 | 396 | case 'percent_product': 397 | $info_message = sprintf( __( 'You will receive a %1$s percent discount on all products within the %2$s category.', 'woocommerce-dynamic-pricing-table' ), floatval( $category_discount_amount ), esc_attr( $current_category_name ) ); 398 | break; 399 | 400 | case 'fixed_product': 401 | $info_message = sprintf( __( 'You will receive %1$s discount on all products within the %2$s category.', 'woocommerce-dynamic-pricing-table' ), wc_price( $category_discount_amount ), esc_attr( $current_category_name ) ); 402 | break; 403 | 404 | } 405 | 406 | // Output category discount message 407 | wc_add_notice( $info_message, 'notice' ); 408 | 409 | } 410 | 411 | } 412 | 413 | } 414 | 415 | /** 416 | * Outputs the category notificaton message. 417 | * @access public 418 | * @since 1.0.0 419 | */ 420 | public function output_dynamic_pricing_category_message() { 421 | $this->category_discount_notification_message(); 422 | } 423 | 424 | } // End Class 425 | --------------------------------------------------------------------------------