Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
795 B
1
Indexable
add_action( 'nrr_coupon_created', function ( WC_Coupon $coupon, NRR_Order $order ) {

    $products = [ 10, 100, 101 ];

    $amount = Nabik_Review_Reminder::get_option( 'coupon.amount' );

    $has_produst = false;

    foreach ( $order->get_items() as $item ) {

        /** @var WC_Product $product */
        $product = $item->get_product();

        if ( ! is_a( $product, WC_Product::class ) ) {
            continue;
        }

        if ( in_array( $product->get_id(), $products ) ) {
            $has_produst = true;
        }
    }
    
    $coupon->set_amount( 5);
    
    if( $has_produst ) {
        $coupon->set_amount( Nabik_Review_Reminder::get_option( 'coupon.amount' ) );
    }

    $coupon->set_discount_type( 'percent' );
    $coupon->save();