Comm3
This commit is contained in:
38
app/Console/Commands/GetFirstOrder.php
Normal file
38
app/Console/Commands/GetFirstOrder.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Codexshaper\WooCommerce\Facades\WooCommerce;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GetFirstOrder extends Command
|
||||
{
|
||||
protected $signature = 'woocommerce:get-first-order';
|
||||
protected $description = 'Get the first order from WooCommerce and display its details';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
// Recupera la lista di ordini, limitando a 1 per ottenere solo il primo
|
||||
$orders = WooCommerce::get('orders', ['per_page' => 1]);
|
||||
|
||||
if (!empty($orders) && isset($orders[0]->id)) {
|
||||
// Mostra i dettagli del primo ordine
|
||||
$this->info('First Order ID: ' . $orders[0]->id);
|
||||
$this->info('Order Status: ' . $orders[0]->status);
|
||||
$this->info('Total: ' . $orders[0]->total);
|
||||
// Aggiungi altri dettagli se necessario
|
||||
} else {
|
||||
$this->error('No orders found.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Gestisci eventuali errori di connessione
|
||||
$this->error('Error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user