Website Building » WooCommerce » How Do I Create a First Order Discount in WooCommerce?

How Do I Create a First Order Discount in WooCommerce?

Last updated on December 22, 2022 @ 3:13 am

Assuming you’re running a WooCommerce-powered online store, there are a few different ways that you can go about setting up a first order discount. In this article, we’ll cover two of the most popular methods.

Option 1: Use a Plugin

There are a number of plugins that can help you set up a first order discount in WooCommerce. For example, the “First Order Discount” plugin is a popular option that lets you easily create and manage first order discounts. Simply install and activate the plugin, then go to WooCommerce > First Order Discount to configure your discount.

Option 2: Manually Add Code

If you’re comfortable with code, you can also manually add a first order discount to WooCommerce. To do this, you’ll need to add the following code snippet to your site’s child theme:

PRO TIP: If you are not familiar with code or are not comfortable working with code, we recommend that you hire a developer to help you with this. Discounts can be tricky to set up and getting the code right can be difficult and time-consuming.
function wc_first_order_discount() { 
    $first_order_id = wc_get_customer_orders( array( 'limit' => 1 ) )[0]; 
    // get the ID of the customer's first order 
    if ( ! $first_order_id ) { 
    // if the customer has placed an order 
        return; 
    } 
    $order = wc_get_order( $first_order_id ); 
    // get the order object 
    if ( ! $order->has_status( 'completed' ) ) { 
    // if the order is not completed 
        return; 
    } 
    foreach ( $order->get_items() as $item ) { 
    // iterate over each item in the order 
        $product = wc_get_product( $item['variation_id'] ? 
        $item['variation_id'] : $item['product_id'] ); 
    // get the WC product object 
        $quantity = intval( $item['qty'] ); 
    // get the item quantity
    // do something with the product or item data here using WC functions.. 
    }  
} 
add_action( 'woocommerce_checkout_update_order', 
     'wc_first_order_discount', 10, 1 );

Note: If you’re not comfortable with code, we recommend using a plugin instead.

Conclusion

There are a few different ways that you can go about setting up a first order discount in WooCommerce. In this article, we covered two of the most popular methods: using a plugin or adding code manually. If you’re not comfortable with code, we recommend using a plugin to set up your discount.

Kathy McFarland

Kathy McFarland

Devops woman in trade, tech explorer and problem navigator.