I want to get custom pricing from functions.php. For woocommerce shop page i want the output as follows. I created a custom taxonamy(team), and i am applying a custom price from the backend.
Eg :
1. Taxonomy : Team1
a) Product Id : 17, Price =222; //Original price $45
b) Product Id : 18, Price = 444; // Original price $55
2. Taxonomy : Team2
a) Product Id : 17, Price =999; //Original price $45
b) Product Id : 18, Price = 888; // Original price $55
How can i get the my example output by using the following code? If any changes or modification please let me know.
I am using the following code :
add_filter( 'woocommerce_get_regular_price', function ($price, $productd ) {
foreach($_SESSION['my_array'] as $id => $price1) :
$regular_price = get_post_meta(get_the_ID(), '_regular_price');
$price = $regular_price[0];
if(get_the_ID() == $id) :
return $price1;
else :
return $price;
endif;
endforeach;
}, 10, 2 );
Thanks, Satya
Once I corrected your parse errors, the code from your comment works.
Modifying that to check for products in a certain taxonomy term, we'll just use
has_term( $term, $taxonomy, $post )
. You will need to adjust the term and tax slugs.Update
Reading your new question, it seems like you are going about this wrong (I could still be misunderstanding you though). If Product 1 is in both Team 1 and Team 2, you could change the price on the taxonomy page using
is_taxonomy("team-A")
but alladd_to_cart()
functionality wouldn't know to use the correct price because there will be no way to discern which price it should use based on term (since the product is in both terms).If you want to display different prices to different groups of Users, then you would need a custom user capability and use that to check when the current user has that cap or not..ex:
current_user_can('team-b')
.