I want to achieve a global discount for all products but only for the 2nd product item.
What do I mean? If the customer buys "Jacket" no discount is given.
Customer buys two of the "Jacket" product. 20% discount is given on the second "Jacket".
Customer buys five of the "Jacket" product. Still only 20% discount on the 2nd "Jacket".
It should work for all both simple and variable products.
I managed to figure this much out and I'm asking for help with how to make the discount apply to only the 2nd item.
Here's the code:
add_filter('woocommerce_product_get_price', 'fifty_percent_on_second_product', 90, 2 );
add_filter('woocommerce_product_get_regular_price', 'fifty_percent_on_second_product', 90, 2 );
function fifty_percent_on_second_product( $price, $product ) {
if ( is_user_logged_in() ) {
I do not know what to do here
}
return $price;
}
Does anyone know how to make this work? If so, please help me.
You could use the Fee API to get a discount (20%) on the 2nd item only this way:
Code goes in function.php file of your active child theme (or active theme). Tested and works.