Search
 
SCRIPT & CODE EXAMPLE
 

PHP

woocommerce hook after order placed

add_action('woocommerce_thankyou', 'enroll_student', 10, 1);
function enroll_student( $order_id ) {
    if ( ! $order_id )
        return;

    // Allow code execution only once 
    if( ! get_post_meta( $order_id, '_thankyou_action_done', true ) ) {

        // Get an instance of the WC_Order object
        $order = wc_get_order( $order_id );

        // Get the order key
        $order_key = $order->get_order_key();

        // Get the order number
        $order_key = $order->get_order_number();

        if($order->is_paid())
            $paid = __('yes');
        else
            $paid = __('no');

        // Loop through order items
        foreach ( $order->get_items() as $item_id => $item ) {

            // Get the product object
            $product = $item->get_product();

            // Get the product Id
            $product_id = $product->get_id();

            // Get the product name
            $product_id = $item->get_name();
        }

        // Output some data
        echo '<p>Order ID: '. $order_id . ' — Order Status: ' . $order->get_status() . ' — Order is paid: ' . $paid . '</p>';

        // Flag the action as done (to avoid repetitions on reload for example)
        $order->update_meta_data( '_thankyou_action_done', true );
        $order->save();
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel get age from date 
Php :: php using composer autoload - own code 
Php :: get min value from array php 
Php :: eloquent get record older than 2 days 
Php :: php ++ 
Php :: loop in loop wordpress 
Php :: wherein elequent 
Php :: how to data save usigng request all laravel 
Php :: custom error page htaccess 
Php :: Get wordpress posts by category name..! 
Php :: how to enable pretty url in yii2 
Php :: laravel realation with has 
Php :: laravel collection max 
Php :: git pull using php 
Php :: what does defined di in php 
Php :: php check if int is odd 
Php :: php associative array join key values 
Php :: how to merge 2 laravel eloquent records 
Php :: php array filter specific keys 
Php :: Laravel eloquent permanent soft delete 
Php :: laravel model wherein 
Php :: delete and return response and nocontent laravel 
Php :: wp add menu page and subpage 
Php :: return with success message laravel 
Php :: how to make a loop that adds numbers to a variable in php 
Php :: laravel 8 websockets 
Php :: luhn algorithm credit card checker php 
Php :: get cookie in laravel 
Php :: PHP str_word_count — Return information about words used in a string 
Php :: laravel blade fontawesome 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =