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 :: how to remove warning in php 
Php :: php messageformatter 
Php :: java script clear rectangle 
Php :: How to remove repetitive values from foreach loop in php laravel 
Php :: laravel save or post 
Php :: setUp() must be compatible with IlluminateFoundationTestingTestCase::setUp() 
Php :: symfony server:start not working 
Php :: load more data on button click in laravel 
Php :: leaf php response json 
Php :: Laravel 9.x Target class does not exist error at login application 
Php :: update php version of particular domain on ubuntu 
Php :: ifmodule condition in htaccess 
Php :: PHP sscanf — Parses input from a string according to a format 
Php :: get vendor store url dokan 
Php :: redaxo urlGenerator, urlGenerator::getId(), Class "UrlGenerator" not found 
Php :: php years 
Php :: PHP not echoing variables when print_r does 
Php :: wp_ajax_nopriv 
Php :: wordpress add block from single.php 
Php :: How to create a contract with Solidity? 
Php :: laravel get user aget from request 
Php :: modal align center yii2 
Php :: Return back to a specific html element - Laravel 
Php :: laravel ignition dark mode 
Php :: make controller laravel history open link 
Php :: php exttends 
Php :: answer to guzzle/psr7 undefine 
Php :: get current date epoch php 
Php :: Comment supprimer les onglets WooCommerce dans WordPress 
Php :: run specific seeder laravel 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =