Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Code to Allow Manual Price Adjustment Based on Inventory
- //Foxyshop 3.3+ required, place this in your functions.php file
- //Manual Price Adjustment
- add_filter('foxyshop_setup_product_info', 'my_custom_price_setting', 10, 2);
- function my_custom_price_setting($product, $product_id) {
- $pricing_levels = get_post_meta($product_id,'_pricing_levels',1);
- if ($pricing_levels) {
- $levels = explode("|", $pricing_levels);
- $current_inventory = (int)$product['inventory_levels'][$product['code']]['count'];
- $setprice = -1;
- foreach($levels AS $level) {
- $current_level = explode("-", $level);
- if ($current_inventory <= (int)$current_level[0] && $setprice < 0) {
- $setprice = (double)$current_level[1];
- }
- }
- if ($setprice >= 0) {
- $product['price'] = $setprice;
- $product['originalprice'] = $product['price'];
- }
- }
- return $product;
- }
- //Show New Field in Admin
- add_action('foxyshop_admin_product_details','my_custom_pricing_levels_meta');
- function my_custom_pricing_levels_meta($post_id) {
- $_pricing_levels = get_post_meta($post_id,'_pricing_levels',1);
- ?>
- <div style="clear:both; padding-top: 6px;"></div>
- <div class="foxyshop_field_control">
- <label for="_pricing_levels"><?php _e('Price Levels'); ?></label>
- <input type="text" name="_pricing_levels" id="_pricing_levels" value="<?php echo esc_attr($_pricing_levels); ?>" />
- </div>
- <div style="clear:both"></div>
- <?php
- }
- //Save New Field
- add_action('foxyshop_save_product','my_custom_pricing_levels_meta_save');
- function my_custom_pricing_levels_meta_save($post_id) {
- global $post_id;
- foxyshop_save_meta_data('_pricing_levels',$_POST['_pricing_levels']);
- return $post_id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement