Hej
Laver en side for en kollega, og vi har det hele til at kører perfekt. Vi kunne dog godt tænke os at det var muligt at trække en lager liste, til når der skal laves optælling. har denne kode og den viser også noget af det vi gerne ville men det fylder bare 26 sider. ville gerne kunne lave så når man åbner den side hvor jeg har lagerlisten på idag, at man så kan vælge fanere for hver kategori, og derunder så se lagerliste for den enkelte kategori..
min koder ser sådan ud. :
<?php
/*
Template Name: Stock Reporter2
*/
if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');
?>
<style>
body { background:white; color:black; width: 95%; margin: 0 auto; }
table { border: 1px solid #000; width: 100%; }
table td, table th { border: 1px solid #000; padding: 3px; }
</style>
<section>
<?php
global $woocommerce;
?>
<h2>Produkter uden Variationer</h2>
<table cellspacing="0" cellpadding="2">
<thead>
<tr>
<th scope="col" style="text-align:left; font-size:15px"><?php _e('Produkt navn', 'woothemes'); ?></th>
<th scope="col" style="text-align:left; font-size:15px"><?php _e('Lager', 'woothemes'); ?></th></tr>
</thead>
<tbody>
<?php$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_manage_stock',
'value' => 'yes'
)
),
'tax_query' => array(
array(
'taxonomy' => 'product_type',
'field' => 'slug',
'terms' => array('simple'),
'operator' => 'IN'
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
$price = (($product->price != "") ? money_format('%i',$product->price) : '0.00');
$regular = (($product->regular_price != "") ? money_format('%i',$product->regular_price) : '0.00');
$sku = (($product->sku != "") ? $product->sku : '<i>None</i>');
?>
<tr>
<td style="font-size:15px"><?php echo $product->get_title(); ?></td>
<td style="font-size:15px"><?php echo $product->stock; ?></td></tr>
<?php
endwhile;
?>
</tbody>
</table>
<h2>Variations</h2>
<table cellspacing="0" cellpadding="2">
<thead>
<tr>
<th scope="col" style="text-align:left; font-size:15px"><?php _e('Produktnavn', 'woothemes'); ?></th>
<th scope="col" style="text-align:left; font-size:15px"><?php _e('Farve / Størrelse', 'woothemes'); ?></th>
<th scope="col" style="text-align:left; font-size:15px"><?php _e('Lager', 'woothemes'); ?></th>
</tr>
</thead>
<tbody>
<?php
$args = array(
'post_type' => 'product_variation',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_stock',
'value' => array('', false, null),
'compare' => 'NOT IN'
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$product = new WC_Product_Variation( $loop->post->ID );
$attrs = array();
if ($product->variation_data != "") {
$terms = $woocommerce->get_attribute_taxonomies();foreach ( $terms as $term) {
$termMap['attribute_pa_'.$term->attribute_name] = $term->attribute_label;
}foreach ($product->variation_data as $attributeKey=>$value) {
if (isset($termMap[$attributeKey])) {
$attrs[] = $termMap[$attributeKey]." : ".$value;
} else {
$attrs[] = $value;
}
}$price = (($product->price != "") ? money_format('%i',$product->price) : '0.00');
$regular = (($product->regular_price != "") ? money_format('%i',$product->regular_price) : '0.00');
$sku = (($product->sku != "") ? $product->sku : '<i>None</i>');
}?>
<tr>
<td style="font-size:15px"><?php echo $product->get_title(); ?></td>
<td style="font-size:15px"><?php echo join(", ",$attrs)?></td>
<td style="font-size:15px"><?php echo $product->stock; ?></td>
</tr>
<?php
endwhile;
?>
</tbody>
</table>
</section>