Changeset 2415322
- Timestamp:
- 11/09/2020 04:54:07 PM (5 years ago)
- Location:
- attribute-calculator/trunk
- Files:
-
- 5 edited
-
AttributeCalculator_OptionsManager.php (modified) (2 diffs)
-
AttributeCalculator_Plugin.php (modified) (4 diffs)
-
attribute-calculator.php (modified) (1 diff)
-
js/calculate.js (modified) (1 diff)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
attribute-calculator/trunk/AttributeCalculator_OptionsManager.php
r2196073 r2415322 282 282 ?> 283 283 <div class="wrap"> 284 <h2><?php _e('System Settings', 'attribute-calculator'); ?></h2> 284 <h2><?php 285 _e('System Settings', 'attribute-calculator'); ?></h2> 285 286 <table cellspacing="1" cellpadding="2"><tbody> 286 287 <tr><td><?php _e('System', 'attribute-calculator'); ?></td><td><?php echo php_uname(); ?></td></tr> … … 359 360 if (is_array($aOptionMeta) && count($aOptionMeta) >= 2) { // Drop-down list 360 361 $choices = array_slice($aOptionMeta, 1); 361 ?> 362 <p><select name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>"> 363 <?php 364 foreach ($choices as $aChoice) { 365 $selected = ($aChoice == $savedOptionValue) ? 'selected' : ''; 366 ?> 367 <option value="<?php echo $aChoice ?>" <?php echo $selected ?>><?php echo $this->getOptionValueI18nString($aChoice) ?></option> 368 <?php 369 } 370 ?> 371 </select></p> 372 <?php 373 374 } 375 else { // Simple input field 376 ?> 377 <p><input type="text" name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>" 378 value="<?php echo esc_attr($savedOptionValue) ?>" size="50"/></p> 379 <?php 380 362 363 ?> 364 <p><select name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>"> 365 <?php 366 foreach ($choices as $aChoice) { 367 $selected = ($aChoice == $savedOptionValue) ? 'selected' : ''; 368 ?> 369 <option value="<?php echo $aChoice ?>" <?php echo $selected ?>><?php echo $this->getOptionValueI18nString($aChoice) ?></option> 370 <?php 371 } 372 ?> 373 </select></p> 374 <?php 375 376 } 377 else { // Simple input field or checkbox 378 if($savedOptionValue=="1" || $savedOptionValue=="0"){ 379 ($savedOptionValue==1)?$check="checked":$check=""; 380 ?><input type="hidden" name="<?php echo $aOptionKey ?>" value="0"/> 381 <p><input type="checkbox" name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>" 382 value="1" <?php echo $check; ?>/></p> 383 <?php 384 385 }else{ 386 ?> 387 <p><input type="text" name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>" 388 value="<?php echo esc_attr($savedOptionValue) ?>" size="50"/></p> 389 <?php 390 } 381 391 } 382 392 } -
attribute-calculator/trunk/AttributeCalculator_Plugin.php
r2196073 r2415322 15 15 //'_version' => array('Installed Version'), // Leave this one commented-out. Uncomment to test upgrades. 16 16 'multiplyBy' => array(__('Slug of the attribute to multiply by. (typically length)', 'uwcpc')), 17 'isEnabled' => array(__(' Enable calculator globally', 'uwcpc'), 'true', 'false')17 'isEnabled' => array(__('1', 'uwcpc')) 18 18 ); 19 19 } … … 69 69 add_action('wp_enqueue_scripts', array(&$this, 'calculate_length_change_script')); 70 70 71 71 add_action('admin_enqueue_scripts', array(&$this, 'attcalc_admin_scripts')); 72 73 add_action('add_meta_boxes', [&$this, 'attcalc_create_metabox']); 72 74 73 75 } 76 public function attcalc_admin_scripts(){ 77 wp_register_script('attcalc-admin', plugin_dir_url(__FILE__) . '/js/calcadmin.js', array('jquery'), '', true ); 78 } 79 public function attcalc_create_metabox(){ 80 if(is_admin()){ 81 add_meta_box('attcalc-control-panel', 'Attribute Calculator Settings', [&$this, 'attcalc_control_panel'], 'product', 'normal', 'high'); 82 } 83 } 84 public function attcalc_control_panel(){ 85 echo 'raaaaaaaaaaaaaaaaaaaaaaawr'; 86 } 74 87 public function calculate_length_change_script(){ 75 88 global $post_type; 76 89 wp_register_script('frontcalc', plugin_dir_url(__FILE__) . '/js/calculate.js', array('jquery'), '', true ); 77 90 78 if($this->getOption('isEnabled') == ' true' && $post_type == 'product'){91 if($this->getOption('isEnabled') == '1' && $post_type == 'product'){ 79 92 global $woocommerce; 80 93 $multiplyBy = $this->getOption('multiplyBy'); … … 124 137 if (isset($_POST[$theMulti]) ) { 125 138 126 $cPrice = substr($_POST[$theMulti], 0, strpos($_POST[$theMulti], '-'));127 139 //$cPrice = substr($_POST[$theMulti], 0, strpos($_POST[$theMulti], '-')); 140 $cPrice = $_POST[$theMulti]; 128 141 $_product_id = $variation_id > 0 ? $variation_id : $product_id; 129 142 130 143 $product = wc_get_product($_product_id); // The WC_Product Object 131 144 $base_price = (float) $product->get_regular_price(); // Get the product regular price 145 146 echo 'post:'. $_POST[$theMulti]; 147 echo '</br>cprice:'.$cPrice; 148 echo '</br>baseprice:'.$base_price; 132 149 133 150 $cart_item_data['custom_data']['base_price'] = $base_price; … … 142 159 return $cart_item_data; 143 160 } 161 162 public function settingsPage() { 163 if (!current_user_can('manage_options')) { 164 wp_die(__('You do not have sufficient permissions to access this page.', 'attribute-calculator')); 165 } 166 wp_enqueue_script('attcalc-admin'); 167 wp_enqueue_style('attcalc-admin-style', plugins_url('/css/admin-style.css', __FILE__)); 168 $optionMetaData = $this->getOptionMetaData(); 169 170 // Save Posted Options 171 if ($optionMetaData != null) { 172 foreach ($optionMetaData as $aOptionKey => $aOptionMeta) { 173 if (isset($_POST[$aOptionKey])) { 174 $this->updateOption($aOptionKey, $_POST[$aOptionKey]); 175 } 176 } 177 } 178 179 // HTML for the page 180 $settingsGroup = get_class($this) . '-settings-group'; 181 ?> 182 <div class="wrap"> 183 <h2><?php _e('System Settings', 'attribute-calculator'); ?></h2> 184 <table cellspacing="1" cellpadding="2"><tbody> 185 <tr><td><?php _e('System', 'attribute-calculator'); ?></td><td><?php echo php_uname(); ?></td></tr> 186 <tr><td><?php _e('PHP Version', 'attribute-calculator'); ?></td> 187 <td><?php echo phpversion(); ?> 188 <?php 189 if (version_compare('5.2', phpversion()) > 0) { 190 echo ' <span style="background-color: #ffcc00;">'; 191 _e('(WARNING: This plugin may not work properly with versions earlier than PHP 5.2)', 'attribute-calculator'); 192 echo '</span>'; 193 } 194 ?> 195 </td> 196 </tr> 197 <tr><td><?php _e('MySQL Version', 'attribute-calculator'); ?></td> 198 <td><?php echo $this->getMySqlVersion() ?> 199 <?php 200 echo ' <span style="background-color: #ffcc00;">'; 201 if (version_compare('5.0', $this->getMySqlVersion()) > 0) { 202 _e('(WARNING: This plugin may not work properly with versions earlier than MySQL 5.0)', 'attribute-calculator'); 203 } 204 echo '</span>'; 205 ?> 206 </td> 207 </tr> 208 </tbody></table> 209 210 <h2><?php echo $this->getPluginDisplayName(); echo ' '; _e('Settings', 'attribute-calculator'); ?></h2> 211 212 <form method="post" action=""> 213 <?php settings_fields($settingsGroup); ?> 214 215 <table class="plugin-options-table"><tbody> 216 <?php 217 if ($optionMetaData != null) { 218 foreach ($optionMetaData as $aOptionKey => $aOptionMeta) { 219 $displayText = is_array($aOptionMeta) ? $aOptionMeta[0] : $aOptionMeta; 220 ($displayText==1 || $displayText==2) ? $displayText = "Enable Globally" : null ; 221 ?> 222 <tr valign="top"> 223 <th scope="row"><p>--<label for="<?php echo $aOptionKey ?>"><?php echo $displayText ?></label></p></th> 224 <td> 225 <?php $this->createFormControl($aOptionKey, $aOptionMeta, $this->getOption($aOptionKey)); ?> 226 </td> 227 </tr> 228 <?php 229 230 } 231 } 232 ?> 233 </tbody></table> 234 <p class="submit"> 235 <input type="submit" class="button-primary" 236 value="<?php _e('Save Changes', 'attribute-calculator') ?>"/> 237 </p> 238 </form> 239 </div> 240 <?php 241 242 } 144 243 145 244 -
attribute-calculator/trunk/attribute-calculator.php
r2196073 r2415322 3 3 Plugin Name: Attribute Calculator 4 4 Plugin URI: http://wordpress.org/extend/plugins/attribute-calculator/ 5 Version: 1. 05 Version: 1.2 6 6 Author: Chris Butler 7 7 Description: Allows you to define an attribute to multiply your product's price in WooCommerce -
attribute-calculator/trunk/js/calculate.js
r2196073 r2415322 16 16 17 17 }else{ 18 //console.log('nope');18 console.log('nope'); 19 19 //$('table.variations').append(theVal.theError); 20 20 } -
attribute-calculator/trunk/readme.txt
r2196087 r2415322 2 2 Contributors:UsusIpse 3 3 Donate link:https://ususipse.com/ 4 Tags:calculator, attribute, attribute-calculator, woocommerce, length, length-calculator, product, product-attribute-calculator, product-length-calculator 4 Tags:calculator, attribute, attribute-calculator, woocommerce, length, length-calculator, product, product-attribute-calculator, product-length-calculator, woocommerce 5 5 License: GPLv3 6 6 License URI: http://www.gnu.org/licenses/gpl-3.0.html 7 7 Requires at least: 3.5 8 Tested up to: 5.2.4 9 Stable tag: 1.0 8 Tested up to: 5.5.3 9 Requires WooCommerce at least: 2.3.6 10 Tested WooCommerce up to: 4.6.2 11 Stable tag: 1.2 10 12 11 13 Multiply price by definable product attribute … … 13 15 == Description == 14 16 15 Expands the functionality of WooCommerce to multiply product price by a definable product attribute. 17 Multiply price by definable product attribute 16 18 17 19 == Installation == 18 20 19 21 After activation you will have a new submenu under Plugins. Follow that to enable and set your attribute name. 20 Make sure you have an attribute with a number and you are good to go. 21 This is designed to work with the attribute slug from Woo. So if you call your attribute 1 Foot, then the slug: 22 1-foot will equal 1 23 but 24 1foot will return a non value, so don't mess with the slugs unless you know what you are doing 25 22 Make sure you have an attribute terms with a number. ex: 1 Foot, 2 Feet, 4 Feet, ect 23 This is designed to work with the attribute term's slug and will multiply by that number. 24 You then need to add this attribute to your variable products along with it's terms, click use for variations and then you can avoid making variations for products that are sold in length, ect. 26 25 27 26 == Frequently Asked Questions == 28 27 28 29 ==To Do == 30 31 Use attribute term description or other field to hold the multiplier. 29 32 30 33 == Screenshots == … … 36 39 == Changelog == 37 40 38 = 0.1 = - addded front end Js function to update the price as the variations are updated. No changes are made to the actual price and theme support may vary. 41 = 1.2 = - Better use of JSON object 42 39 43 - Initial Revision 40 44 = 1.0 = - Push to GitHub and Automatic 45 = 0.1 = - addded front end Js function to update the price as the variations are updated. No changes are made to the actual price and theme support may vary.
Note: See TracChangeset
for help on using the changeset viewer.