1) Качаем
https://srd.wordpress.org/plugins/first-order-discount/
2) Правим код плагина ( у меня тут ещё +10% скидка для зарегестрированных пользователей)
function first_order_add_fee() {
global $wpdb, $woocommerce;
if ( is_user_logged_in() ) {
$customer_id = get_current_user_id();
$orderNumCheck = wc_get_customer_order_count( $customer_id ); // count orders by current customer
$options = get_option( 'first_order_add_settings' );
$discountType = $options['first_order_choose'];
$discountValue = $options['first_order_add_value'];
$subtotal = WC()->cart->cart_contents_total;
$discount = $discountValue/100;
$check5order = $orderNumCheck + 1;
if ($check5order % 5 == 0) {
$product_id = 1802;
$found = false;
//check if product already in cart
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product_id )
$found = true;
}
// if product not found, add it
if ( ! $found )
WC()->cart->add_to_cart( $product_id );
} else {
// if no products in cart, add it
WC()->cart->add_to_cart( $product_id );
}
}
WC()->cart->add_fee( 'Скидка 10%', -$subtotal*$discount );
}
}
function add_custom_price( $cart_object ) {
foreach ( $cart_object->cart_contents as $key => $value ) {
if ($value["product_id"] == "1802") {
$currPrice = $value['data']->price;
$currQuant = $value["quantity"];
$totalPrice = $currPrice * $currQuant;
$salePrice = $totalPrice - $currPrice;
$salingPrice = $salePrice/$currQuant;
$value['data']->price = $salingPrice;
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
add_action( 'woocommerce_cart_calculate_fees','first_order_add_fee' );