Created
October 5, 2015 10:55
-
-
Save wp-kitten/cef024775684f52129ea to your computer and use it in GitHub Desktop.
WooCommerce - Different prices for users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: WC Price | |
| * Plugin URI: http://localhost | |
| * Description: WC set different prices | |
| * Version: 1.0 | |
| * Author: kso | |
| * Requires at least: 4.1 | |
| * Tested up to: 4.3 | |
| * | |
| * Text Domain: whatever | |
| */ | |
| // http://stackoverflow.com/questions/15090258/woocommerce-custom-price-using-get-price-function | |
| function return_custom_price($price, $product) { | |
| global $post, $woocommerce; | |
| $post_id = $post->ID; | |
| // Prevent conflicts with order pages and products, peace of mind. | |
| if($post_id == '9' || $post_id == '10' || $post_id == '17' || $post_id == '53' || $post_id == ''){ | |
| // cart, checkout, , order received, order now | |
| $post_id = $product->id; | |
| } | |
| if(! is_user_logged_in()){ | |
| $new_price = $price; | |
| } | |
| else { | |
| // | |
| $new_price = '10'; | |
| } | |
| if( is_admin() && $_GET['post_type']=='product' ){ | |
| return $price; | |
| } else { | |
| return $new_price; | |
| } | |
| } | |
| add_filter('woocommerce_get_price', 'return_custom_price', $product, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment