add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 10, 1);
function add_custom_price( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
foreach ( $cart_object->get_cart() as $cart_item ) {
## Price calculation ##
$price = $cart_item['data']->price * 12;
## Set the price with WooCommerce compatibility ##
if ( version_compare( WC_VERSION, '3.0', '<' ) ) {
$cart_item['data']->price = $price; // Before WC 3.0
} else {
$cart_item['data']->set_price( $price ); // WC 3.0+
}
}
}