// === Lageränderungen mitschreiben === add_action('woocommerce_product_set_stock', function($product){ global $wpdb; $table = $wpdb->prefix . 'stock_log'; // Tabelle einmalig anlegen if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") != $table) { $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, product_id bigint(20) unsigned NOT NULL, old_stock int NOT NULL, new_stock int NOT NULL, changed_at datetime NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } // alten und neuen Bestand abholen $old_stock = $product->get_changes()['stock_quantity'] ?? $product->get_stock_quantity(); $new_stock = $product->get_stock_quantity(); if ($old_stock != $new_stock) { $wpdb->insert($table, [ 'product_id' => $product->get_id(), 'old_stock' => intval($old_stock), 'new_stock' => intval($new_stock), 'changed_at' => current_time('mysql') ]); } }, 10, 1); // === Admin-Menü: Log anzeigen === add_action('admin_menu', function(){ add_menu_page( 'Bestands-Log', 'Bestands-Log', 'manage_woocommerce', 'stock-log', function(){ global $wpdb; $table = $wpdb->prefix . 'stock_log'; $rows = $wpdb->get_results("SELECT * FROM $table ORDER BY changed_at DESC LIMIT 50"); echo '

Letzte Bestandsänderungen

'; foreach($rows as $r){ $product = wc_get_product($r->product_id); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
IDProduktAltNeuZeit
' . $r->id . '' . ($product ? $product->get_name() : $r->product_id) . '' . $r->old_stock . '' . $r->new_stock . '' . $r->changed_at . '
'; } ); }); Kommentare auf Elektromobil Discounter unschlagbare Preise! Mon, 01 Oct 2018 21:23:43 +0000 hourly 1 https://wordpress.org/?v=6.7.5 Kommentar zu Hello world! von A WordPress Commenter https://elektromobil-discounter.de/2018/10/01/hello-world/#comment-1 Mon, 01 Oct 2018 21:23:43 +0000 http://elektromobil-discounter.de/?p=1#comment-1 Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from Gravatar.

]]>