Thursday, 14 December 2017

Auto Complete all WooCommerce orders

/**
 * Auto Complete all WooCommerce orders.
 */
add_action( 'woocommerce_thankyou', 'custom_woocommerce_auto_complete_order' );
function custom_woocommerce_auto_complete_order( $order_id ) {
    if ( ! $order_id ) {
        return;
    }

    $order = wc_get_order( $order_id );

    /*  Customized Solution by Nucleus System */
    // Set HERE your targetted products IDs:
    $targetted_products = array( 3038 ); //if product id is crony

    $order = wc_get_order( $order_id );

    if ( $order->get_user_id() > 0 ) {
        foreach ( $order->get_items() as $order_item ) {
            // Here we detect if the a target product is part of this order items
            if ( in_array( $order_item['product_id'], $targetted_products ) ){

                // I think tha this is not really needed as it's set when an order has been paid…
                update_user_meta( $order->get_user_id(), 'paying_customer', 1 ); // 1 => true

                // Remove all roles and set 'editor' as user role (for current user)
                $user = new WP_User( $order->get_user_id() );
                $user->set_role( 'crony' );
                // Product is found, we break the loop…
                break;
            }
        }
    }

    $order->update_status( 'completed' );
}
//
// add_action( 'woocommerce_order_status_completed', 'custom_action_on_completed_customer_email_notification' );
// function custom_action_on_completed_customer_email_notification( $order_id ) {
//
//     // Set HERE your targetted products IDs:
//     $targetted_products = array( 3038 );
//
//     $order = wc_get_order( $order_id );
//
//     if ( $order->get_user_id() > 0 ) {
//         foreach ( $order->get_items() as $order_item ) {
//             // Here we detect if the a target product is part of this order items
//             if ( in_array( $order_item['product_id'], $targetted_products ) ){
//
//                 // I think tha this is not really needed as it's set when an order has been paid…
//                 update_user_meta( $order->get_user_id(), 'paying_customer', 1 ); // 1 => true
//
//                 // Remove all roles and set 'editor' as user role (for current user)
//                 $user = new WP_User( $order->get_user_id() );
//                 $user->set_role( 'crony' );
//                 $user->add_role( 'subscriber' );
//
//                 // Product is found, we break the loop…
//                 break;
//             }
//         }
//     }
// }

email mailto: pretext

 <a href="mailto:designoutsourced.com+info@gmail.com?subject=Maklumat%20lanjut%20pakej&body=Hai,%20saya%20berminat%20tahu%20lebi...