Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'admin_init', 'jtd_add_theme_caps');
- function jtd_add_theme_caps() {
- /*
- $asia = add_role('asia_distributor', 'Asia Distributor', array(
- 'read' => true,
- 'edit_posts' => false,
- 'delete_posts' => false
- ));
- */ // only has to run once - or use the Members plugin to create these
- $retail = get_role( 'retailer' );
- $whole = get_role( 'wholesaler' );
- $asia = get_role( 'asia_distributor' );
- $retail->add_cap( 'retail_pricing' ); // Actually called Distributor on back end
- $whole->add_cap( 'wholesale_pricing' );
- $asia->add_cap( 'asia_pricing' );
- }
- //Manual Price Adjustment
- add_filter('foxyshop_setup_product_info', 'jtd_members_price', 10, 2);
- function jtd_members_price($product, $product_id) {
- if ( !function_exists('wp_get_current_user') || !is_user_logged_in() ) return $product;
- $current_user = wp_get_current_user();
- $current_user_id = $current_user->ID;
- $new_price = '';
- if ( current_user_can( 'retail_pricing' ) ) { // Retailer account
- // get Retailer pricing
- $new_price = get_post_meta( $product_id, '_jtd_retail_price', true );
- } elseif ( current_user_can( 'wholesale_pricing' ) ) { // Wholesaler Account
- // get Wholesale pricing
- $new_price = get_post_meta( $product_id, '_jtd_wholesale_price', true );
- } elseif ( current_user_can( 'asia_pricing' ) ) { // Asia Account
- // get Wholesale pricing
- $new_price = get_post_meta( $product_id, '_jtd_asia_price', true );
- } else {
- return $product;
- }
- if ( !empty( $new_price ) ) {
- $newprice = $new_price;
- $product['price'] = $newprice;
- }
- return $product;
- }
- //Show New Field in Admin
- add_action( 'foxyshop_admin_product_details', 'jtd_custom_pricing_levels_meta' );
- function jtd_custom_pricing_levels_meta($post_id) {
- $retail_price = get_post_meta( $post_id, '_jtd_retail_price', true );
- $asia_price = get_post_meta( $post_id, '_jtd_asia_price', true );
- $wholesale_price = get_post_meta( $post_id, '_jtd_wholesale_price', true );
- ?>
- <h4>Distributor/Wholesale Pricing</h4>
- <div class="foxyshop_field_control">
- <label for="_jtd_retail_price">Distributor</label>
- <input type="text" name="_jtd_retail_price" id="_jtd_retail_price" value="<?php echo $retail_price ?>" />
- </div>
- <div class="foxyshop_field_control">
- <label for="_jtd_asia_price">Asia Distrib</label>
- <input type="text" name="_jtd_asia_price" id="_jtd_asia_price" value="<?php echo $asia_price ?>" />
- </div>
- <div class="foxyshop_field_control">
- <label for="_jtd_wholesale_price">Wholesaler</label>
- <input type="text" name="_jtd_wholesale_price" id="_jtd_wholesale_price" value="<?php echo $wholesale_price ?>" />
- </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;
- if ( isset( $_POST['_jtd_retail_price'] ) ) {
- foxyshop_save_meta_data( '_jtd_retail_price', strip_tags( $_POST['_jtd_retail_price'] ) );
- }
- if ( isset( $_POST['_jtd_asia_price'] ) ) {
- foxyshop_save_meta_data( '_jtd_asia_price', strip_tags( $_POST['_jtd_asia_price'] ) );
- }
- if ( isset( $_POST['_jtd_wholesale_price'] ) ) {
- foxyshop_save_meta_data( '_jtd_wholesale_price', strip_tags( $_POST['_jtd_wholesale_price'] ) );
- }
- return $post_id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement