I want to achieve this: when auction is ended, user click "Pay Now", product is added in user's cart but final price (eg. $50) is increased by 10% Goal is to increase final auction price by 10%, winner should pay 10% more.
I tried to increase with "WooCommerce Dynamic Pricing & Discounts by RightPress" by targeting products with "_auction_start_price" meta data - no luck. Also I tried with this code:
function before_calculate_totals( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
// Iterate through each cart item
foreach ( $cart->get_cart() as $cart_item ) {
$product_id = $cart_item['product_id'];
$product_price = $cart_item['data']->get_price(); // get the price
$meta = get_post_meta($product_id, '_auction_start_price', true);
if ($meta > 0) {
$new_price = $product_price+($product_price*0.1); // add 10% to price
} else {
$new_price = $product_price+100;
}
$cart_item['data']->set_price(floatval($new_price)); // set new price
}
}
add_action( 'woocommerce_before_calculate_totals', 'before_calculate_totals', 10, 1 );
This code works with normal simple products, but not with auction items.
I have Woocommerce 3.0+