Add "Sku" and "Stock"
-
The plugin is very easy to change the prices.
But I would like to add the ability to display “sku” and “stock”, as well as their editing and saving.I changed the files and the output achieved “sku” and “stock” of the table along with prices, but when you save the table, “sku” and “stock” of the goods is retained in the void.
Tell me that I did not consider please.My code:
woocommerce-prices.php$posts = get_posts($args); // Build grid data $data = array(); $url = plugins_url('images/delete.png', __FILE__); foreach ($posts as $post) { $sku = get_post_meta($post->ID, '_sku', true); $stock = get_post_meta($post->ID, '_stock', true); // Get prices $regular_price = get_post_meta($post->ID, '_regular_price', true); if ('' != $regular_price) { $regular_price = wc_format_localized_price($regular_price); } ......
// Create row object $product = new stdClass(); $product->ID = $post->ID; $product->sku = $sku; $product->stock = $stock; $product->title = $post->post_title; ....
$products = $_POST['products']; // Update sale price and dates foreach ($products as $product) { $ID = $product['ID']; $sku = $product['sku']; $stock = $product['stock']; $regular_price = wc_format_decimal($product['regular_price']); $sale_price = wc_format_decimal($product['sale_price']); $sale_from = strtotime($product['sale_from']); $sale_to = strtotime($product['sale_to']); // Update prices update_post_meta($ID, '_sku', $sku); update_post_meta($ID, '_stock', $stock); update_post_meta($ID, '_regular_price', $regular_price); update_post_meta($ID, '_sale_price', $sale_price); ....
script.js:
var gridColumns = [ checkboxSelector.getColumnDefinition(), {id: 'sku', name: 'Арт.', field: 'sku', width: 60, editor: Slick.Editors.Text}, {id: 'stock', name: 'Кол-во', field: 'stock', width:60, editor: Slick.Editors.Text}, {id: 'title', name: 'Товар', field: 'title', width: 290}, {id: 'regular_price', name: 'Цена', field: 'regular_price', editor: Slick.Editors.Text, width: 60}, {id: 'sale_price', name: 'Цена распр.', field: 'sale_price', editor: Slick.Editors.Text, width: 100}, {id: 'sale_from', name: 'Распр. с', field: 'sale_from', editor: customDateEditor, width: 100}, {id: 'sale_to', name: 'Распр. до', field: 'sale_to', editor: customDateEditor, width: 100} ]; ....
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Add "Sku" and "Stock"’ is closed to new replies.