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

woocommerce on order complete hook

add_action('woocommerce_thankyou', 'update_order_in_thirdparty', 10, 1);
function update_order_in_thirdparty($order_id)
{
	if (!$order_id)
		return;
  
    $order = wc_get_order( $order_id );
    $user = $order->get_user();
    if( $user ){
        // do something with the user
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: wp_cache_get 
Php :: how create migration in laravel 
Php :: laravel module create module 
Php :: Eloquent models events 
Php :: CSV File Read using PHP fgetcsv() 
Php :: wp_list_pluck 
Php :: php .= 
Php :: cambiare pagina php 
Php :: session_start cookie lifetime 
Php :: wherehas laravel search 
Php :: laravel livewire-datatable delete column pop up issue 
Php :: php proper function comments 
Php :: Eloquent where date methods 
Php :: filesize in php 
Php :: throttle laravel 
Php :: contact form 7 checkbox2 
Php :: how to set select option value dynamically in php 
Php :: get recoed between two datetime laravel 
Php :: php get bool from string 
Php :: php replace br 
Php :: laravel DB wherein 
Php :: laravel Impossible to create the root directory 
Php :: check the route type in laravel 
Php :: laravel image store 
Php :: delete data with ajax in php 
Php :: create symfony 4 project 
Php :: laravel all fillable 
Php :: function inside model laravel 
Php :: url segment laravel 
Php :: replace word in string php 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =