به وبلاگ ما خوش آمدید - لطفا صفحه را تا پایان مشاهده کنید
وو کــا مرس جانبی 263
شرطی کردن نمایش قیمت ها:
abstract-wc-product
خط 920
افزودن دستور شرطی
if( !current_user_can('subscriber') && !current_user_can('administrator') && ( !is_admin() || is_ajax() ) )
            {
            $price = $display_regular_price;
            }

برچسب ها :
| لینک ثابت | نسخه قابل چاپ | امتیاز :
rss نوشته شده در تاریخ 13 اسفند 1392 و در ساعت : 11:39 - نویسنده : ســـاناز
قیمت عمده فروشی
WooCommerce – Add custom pricing method for products

WooCommerce have two type of pricing method form Simple Product - Regular and Sale. This method is used for any kind of registered user or un registered shopper. Now, what if you wanna add a pricing for some specified user roles ? there is plugin for that ofcourse. But how can you make it without using any plugin ? here’s a solution.

Adding some codes, we can also add an extra pricing method, ex: Wholesale Price. And then set this price for a specific user role. In this article, i will show you how you can achieve that. Note: in this article we are calling the new pricing as – Wholesale Pricing & Editor is the specific user role to whom the price will be applicable for.

Step One – Adding the input field

First, we need to add Wholesale Pricing input to the product editing page. Here’s the code -

add_action( 'woocommerce_product_options_pricing', 'wholesale_product_options_pricing' ); function wholesale_product_options_pricing() { woocommerce_wp_text_input( array( 'id' => '_wholesale_price', 'class' => 'wc_input_wholesale_price short', 'label' => __( 'Wholesale Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')', 'type' => 'number' )); }

After you have added this in your themes functions.php or plugin file, you would see a new input appears under the sale price input (note: Simple Product only).




Step Two – Saving the price

Next we need to save the wholesale price value.

add_action( 'woocommerce_process_product_meta_simple', 'wholesale_process_product_meta_simple', 10, 1 ); function wholesale_process_product_meta_simple( $product_id ) { if( isset($_POST['_wholesale_price']) && $_POST['_wholesale_price'] > 0 ) { update_post_meta( $product_id, '_wholesale_price', $_POST['_wholesale_price'] ); } }

This code will save the entered value for wholesale price with the product with a custom meta ‘_wholesale_price’.

Step Three – Frontend pricing filter

Now, to Assign the wholesale price for ‘Editor’ we will need to hook into woocommerce_get_price filter.

add_filter( 'woocommerce_get_price', 'wholesale_get_price', 10, 2); function wholesale_get_price( $price, $product ) { if( current_user_can('editor') && ( !is_admin() || is_ajax() ) ) { if( $product->is_type('simple') && get_post_meta( $product->id, '_wholesale_price', true ) > 0 ) { $price = get_post_meta( $product->id, '_wholesale_price', true ); } } return $price; }

All done, Now you can check how it is working by login with any Editor’s credentials and you should see the product is valued with the wholesale price rather than the sale/regular price. However, all other user/customer should get the sale price as usual.

Thanks.


برچسب ها :
| لینک ثابت | نسخه قابل چاپ | امتیاز :
rss نوشته شده در تاریخ 10 اسفند 1392 و در ساعت : 01:53 - نویسنده : ســـاناز
آخرین مطالب نوشته شده
  • کد نمونه پخش
  • تست پخش آهنگ
  • NOSRAT 79
  • NOSRAT 77
  • NOSRAT 78
  • NOSRAT 85
  • test2
  • جالب ترین های اینترنتی
  • per month
  • Body Language for Leaders with Carol Kinsey Goman
  • latest
  • ssssssssssssss
  • گزارش کار اینویتیشن
  • سوده
  • علی سورس
  • صفحه به صفحه ی تاینی
  • movies
  • لینک
  • hoit
  • 3 وبلاگ سایت سلامتی
  • Copyright © 2010 by http://imahdio.samenblog.com