Skip to content

Instantly share code, notes, and snippets.

@david-huanca
Last active September 17, 2020 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-huanca/b2922ef0d08c4b762424cb40683beeb2 to your computer and use it in GitHub Desktop.
Save david-huanca/b2922ef0d08c4b762424cb40683beeb2 to your computer and use it in GitHub Desktop.
Example
<?php
namespace DAVIDBUILDER;
use DAVIDBUILDER\EducativaSOAPController;
class WooController
{
public $mailAdmin;
public function __construct()
{
$this->mailAdmin = 'dhuanca@samnaz.org';
}
public static function woocommerce_order_status_completed($order_id){
$order = wc_get_order( $order_id );
$order_status = $order->get_status();
$user = $order->get_user();
error_log("Orden N $order_id => $user->user_email" );
// Iterating through each WC_Order_Item_Product objects
foreach ($order->get_items() as $item_key => $item ):
## Using WC_Order_Item methods ##
// Item ID is directly accessible from the $item_key in the foreach loop or
$item_id = $item->get_id();
## Using WC_Order_Item_Product methods ##
$product = $item->get_product(); // Get the WC_Product object
$product_id = $item->get_product_id(); // the Product id
$variation_id = $item->get_variation_id(); // the Variation id
$item_type = $item->get_type(); // Type of the order item ("line_item")
$item_name = $item->get_name();
$quantity = $item->get_quantity();
$tax_class = $item->get_tax_class();
$line_subtotal = $item->get_subtotal(); // Line subtotal (non discounted)
$line_subtotal_tax = $item->get_subtotal_tax(); // Line subtotal tax (non discounted)
$line_total = $item->get_total(); // Line total (discounted)
$line_total_tax = $item->get_total_tax(); // Line total tax (discounted)
## Access Order Items data properties (in an array of values) ##
$item_data = $item->get_data();
$product_name = $item_data['name'];
$product_id = $item_data['product_id'];
$variation_id = $item_data['variation_id'];
$quantity = $item_data['quantity'];
$tax_class = $item_data['tax_class'];
$line_subtotal = $item_data['subtotal'];
$line_subtotal_tax = $item_data['subtotal_tax'];
$line_total = $item_data['total'];
$line_total_tax = $item_data['total_tax'];
// Get data from The WC_product object using methods (examples)
$product = $item->get_product(); // Get the WC_Product object
$product_type = $product->get_type();
$product_sku = $product->get_sku();
$product_price = $product->get_price();
$stock_quantity = $product->get_stock_quantity();
error_log("\t* $product_name [$product_sku]" );
endforeach;
$soap = new EducativaSOAPController;
if(!$controller->userExist($user->user_email)){
$usuario = [
'administrador_usuario' => false,
'id_usuario' => $user->user_email,
'nombre' => $user->first_name,
'apellido' => $user->last_name,
'clave' => '123456',
'email' => $user->user_email
];
$grupo = [
'administrador_grupo' => false,
'estado' => 1,
'id_grupo' => 127,
'perfil' => 'I'
];
$controller->createUser($usuario, $grupo);
error_log('The user has been created successful');
}
error_log("Test Soap N $order_id =>" . $soap->testSoap());
return $order_id;
}
public static function register_new_user($user_id)
{ $mail = $this->$mailAdmin;
wp_mail( $mail, "sally's blog updated", 'I just put something on my blog: http://blog.example.com' );
return $user_id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment