Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created December 5, 2011 20:18

Revisions

  1. mikejolley revised this gist Feb 17, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion template-stock-report.php
    Original file line number Diff line number Diff line change
    @@ -113,7 +113,7 @@

    while ( $loop->have_posts() ) : $loop->the_post();

    global $product;
    $product = new WC_Product_Variation( $loop->post->ID );
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
  2. mikejolley revised this gist Feb 15, 2012. 1 changed file with 4 additions and 8 deletions.
    12 changes: 4 additions & 8 deletions template-stock-report.php
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@
    'order' => 'ASC',
    'meta_query' => array(
    array(
    'key' => 'manage_stock',
    'key' => '_manage_stock',
    'value' => 'yes'
    )
    ),
    @@ -67,9 +67,7 @@

    while ( $loop->have_posts() ) : $loop->the_post();

    $product_id = $loop->post->ID;

    $product = &new woocommerce_product($product_id);
    global $product;
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    @@ -104,7 +102,7 @@
    'order' => 'ASC',
    'meta_query' => array(
    array(
    'key' => 'stock',
    'key' => '_stock',
    'value' => array('', false, null),
    'compare' => 'NOT IN'
    )
    @@ -115,9 +113,7 @@

    while ( $loop->have_posts() ) : $loop->the_post();

    $product_id = $loop->post->ID;

    $product = &new woocommerce_product($product_id);
    global $product;
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
  3. mikejolley revised this gist Dec 6, 2011. 1 changed file with 120 additions and 120 deletions.
    240 changes: 120 additions & 120 deletions template-stock-report.php
    Original file line number Diff line number Diff line change
    @@ -7,129 +7,129 @@
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php _e('Stock Report'); ?></title>
    <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: 6px; }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php _e('Stock Report'); ?></title>
    <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: 6px; }
    </style>
    </head>
    <body>
    <header>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1 class="title"><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <?php endwhile; endif; ?>
    </header>
    <section>
    <?php
    <header>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1 class="title"><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <?php endwhile; endif; ?>
    </header>
    <section>
    <?php

    global $woocommerce;
    ?>
    <table cellspacing="0" cellpadding="2">
    <thead>
    <tr>
    <th scope="col" style="text-align:left;"><?php _e('Product', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', 'woothemes'); ?></th>
    </tr>
    </thead>
    <tbody>
    <?php
    global $woocommerce;
    ?>
    <table cellspacing="0" cellpadding="2">
    <thead>
    <tr>
    <th scope="col" style="text-align:left;"><?php _e('Product', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', '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();
    $product_id = $loop->post->ID;
    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?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;"><?php _e('Variation', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Parent', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', '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_id = $loop->post->ID;
    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo get_the_title( $loop->post->post_parent ); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?php echo $product->stock; ?></td>
    </tr>
    <?php
    endwhile;
    ?>
    </tbody>
    </table>
    $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();
    $product_id = $loop->post->ID;
    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?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;"><?php _e('Variation', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Parent', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', '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_id = $loop->post->ID;
    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo get_the_title( $loop->post->post_parent ); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?php echo $product->stock; ?></td>
    </tr>
    <?php
    endwhile;
    ?>
    </tbody>
    </table>
    </body>
    </html>
  4. mikejolley revised this gist Dec 6, 2011. 1 changed file with 120 additions and 120 deletions.
    240 changes: 120 additions & 120 deletions template-stock-report.php
    Original file line number Diff line number Diff line change
    @@ -7,129 +7,129 @@
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php _e('Stock Report'); ?></title>
    <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: 6px; }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php _e('Stock Report'); ?></title>
    <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: 6px; }
    </style>
    </head>
    <body>
    <header>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1 class="title"><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <?php endwhile; endif; ?>
    </header>
    <section>
    <?php
    <header>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <h1 class="title"><?php the_title(); ?></h1>
    <?php the_content(); ?>
    <?php endwhile; endif; ?>
    </header>
    <section>
    <?php

    global $woocommerce;
    ?>
    <table cellspacing="0" cellpadding="2">
    <thead>
    <tr>
    <th scope="col" style="text-align:left;"><?php _e('Product', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', 'woothemes'); ?></th>
    </tr>
    </thead>
    <tbody>
    <?php
    global $woocommerce;
    ?>
    <table cellspacing="0" cellpadding="2">
    <thead>
    <tr>
    <th scope="col" style="text-align:left;"><?php _e('Product', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', '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();
    $product_id = $loop->post->ID;
    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?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;"><?php _e('Variation', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Parent', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', '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_id = $loop->post->ID;
    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo get_the_title( $loop->post->post_parent ); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?php echo $product->stock; ?></td>
    </tr>
    <?php
    endwhile;
    ?>
    </tbody>
    </table>
    $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();
    $product_id = $loop->post->ID;
    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?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;"><?php _e('Variation', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Parent', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', '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_id = $loop->post->ID;
    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo get_the_title( $loop->post->post_parent ); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?php echo $product->stock; ?></td>
    </tr>
    <?php
    endwhile;
    ?>
    </tbody>
    </table>
    </body>
    </html>
  5. mikejolley revised this gist Dec 5, 2011. 1 changed file with 77 additions and 19 deletions.
    96 changes: 77 additions & 19 deletions template-stock-report.php
    Original file line number Diff line number Diff line change
    @@ -27,25 +27,8 @@
    </header>
    <section>
    <?php

    global $woocommerce;

    $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'
    )
    )
    );

    $loop = new WP_Query( $args );

    ?>
    <table cellspacing="0" cellpadding="2">
    <thead>
    @@ -57,7 +40,79 @@
    </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();

    $product_id = $loop->post->ID;

    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?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;"><?php _e('Variation', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Parent', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', '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_id = $loop->post->ID;
    @@ -66,11 +121,14 @@
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo get_the_title( $loop->post->post_parent ); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?php echo $product->stock; ?></td>
    </tr>
    <?php
    endwhile; ?>
    endwhile;

    ?>
    </tbody>
    </table>
    </body>
  6. mikejolley created this gist Dec 5, 2011.
    77 changes: 77 additions & 0 deletions template-stock-report.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    <?php
    /*
    Template Name: Stock Report :)
    */
    if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php _e('Stock Report'); ?></title>
    <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: 6px; }
    </style>
    </head>
    <body>
    <header>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <h1 class="title"><?php the_title(); ?></h1>

    <?php the_content(); ?>

    <?php endwhile; endif; ?>
    </header>
    <section>
    <?php

    global $woocommerce;

    $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'
    )
    )
    );

    $loop = new WP_Query( $args );

    ?>
    <table cellspacing="0" cellpadding="2">
    <thead>
    <tr>
    <th scope="col" style="text-align:left;"><?php _e('Product', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('SKU', 'woothemes'); ?></th>
    <th scope="col" style="text-align:left;"><?php _e('Stock', 'woothemes'); ?></th>
    </tr>
    </thead>
    <tbody>
    <?php

    while ( $loop->have_posts() ) : $loop->the_post();

    $product_id = $loop->post->ID;

    $product = &new woocommerce_product($product_id);
    ?>
    <tr>
    <td><?php echo $product->get_title(); ?></td>
    <td><?php echo $product->sku; ?></td>
    <td><?php echo $product->stock; ?></td>
    </tr>
    <?php
    endwhile; ?>
    </tbody>
    </table>
    </body>
    </html>