<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
		>
<channel>
<title>هر روز</title>
<description></description>
<atom:link href="http://imahdio.samenblog.com/rss/136/" rel="self" type="application/rss+xml"/>
<link>http://imahdio.samenblog.com/</link>
<generator>RSS Generated by SamenBlog.com</generator><item>
<title>قیمت عمده فروشی</title>
<link>http://imahdio.samenblog.com/136.html</link><category></category>
<description><![CDATA[WooCommerce – Add custom pricing method for products
	


				<div style="text-align: left;" id="post_content" itemtype="http://schema.org/articleBody" itemprop="text">
					<p>WooCommerce have two type of pricing method form <strong>Simple Product</strong> -&nbsp;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.</p>
<p>Adding some codes, we can also add an extra pricing method, ex: <strong>Wholesale Price</strong>. 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 – <strong>Wholesale Pricing</strong> &amp; <strong>Editor</strong> is the specific user role to whom the price will be applicable for.</p>

Step One – Adding the input field
<p>First, we need to add Wholesale Pricing input to the product editing page. Here’s the code -</p>
add_action( 'woocommerce_product_options_pricing', 'wholesale_product_options_pricing' );
function wholesale_product_options_pricing()
{
	woocommerce_wp_text_input( array( 
		'id' =&gt; '_wholesale_price',
		'class' =&gt; 'wc_input_wholesale_price short',
		'label' =&gt; __( 'Wholesale Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')',
		'type' =&gt; 'number'
	));
}

<p>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).</p>
<div class="box aligncenter"><br /><br /><img src="http://www.samenblog.com/uploads/i/imahdio/180639.jpg" /><br /></div>

Step Two – Saving the price
<p>Next we need to save the wholesale price value. </p>
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']) &amp;&amp; $_POST['_wholesale_price'] &gt; 0 )
	{
		update_post_meta( $product_id, '_wholesale_price', $_POST['_wholesale_price'] );
	}
}

<p>This code will save the entered value for wholesale price with the product with a custom meta ‘_wholesale_price’.</p>

Step Three – Frontend pricing filter
<p>Now, to Assign the wholesale price for ‘Editor’ we will need to hook into woocommerce_get_price filter.</p>
add_filter( 'woocommerce_get_price', 'wholesale_get_price', 10, 2);
function wholesale_get_price( $price, $product )
{
	if( current_user_can('editor') &amp;&amp; ( !is_admin() || is_ajax() ) )
	{
		if( $product-&gt;is_type('simple') &amp;&amp; get_post_meta( $product-&gt;id, '_wholesale_price', true ) &gt; 0 )
		{
			$price = get_post_meta( $product-&gt;id, '_wholesale_price', true );
		}
	}

	return $price;
}

<p>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.</p>
<p>Thanks.</p></div>
			
]]></description>
<pubDate>Sat, 1 Mar 2014 10:23:12 GMT</pubDate>
<dc:creator>imahdio</dc:creator>
<guid isPermaLink="false">http://imahdio.samenblog.com/136.html</guid>
</item>
</channel>
</rss>