WooCommerce-印刷加工订单

时间:2015-11-11 作者:Dylan van Rijnberk

在我们的WooCommerce网站上,我们有一个PHP页面,可以生成处理订单。现在,我需要在表中显示SKU,但我不知道如何操作:)

以下是当前页面的示例:Example

这是PHP模板:

<?php
/*
Template Name: Print Processing Orders Full
*/
if (!is_user_logged_in() || !current_user_can(\'manage_options\'));
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php _e(\'Processing Orders\'); ?></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; }
    article { border-top: 2px dashed #000; padding: 20px 0; }
</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\'         => \'shop_order\',
    \'post_status\'       => \'publish\',
            \'posts_per_page\' => -1,
    \'tax_query\' => array(
                array(
                    \'taxonomy\' => \'shop_order_status\',
                    \'field\' => \'slug\',
                    \'terms\' => array(\'processing\')
                )
            )
);

$loop = new WP_Query( $args );

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

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

    $order = new WC_Order($order_id);

    ?>
    <article>
        <header>
            <h2>Order #<?php echo $order_id; ?> &mdash; <time datetime="<?php the_time(\'c\'); ?>"><?php echo the_time(\'d/m/Y\'); ?></time></h2>
        </header>
        <table cellspacing="0" cellpadding="2">
            <thead>
                <tr>
                    <th scope="col" style="text-align:left;"><?php _e(\'sku\', \'woothemes\'); ?></th>
                    <th scope="col" style="text-align:left;"><?php _e(\'Product\', \'woothemes\'); ?></th>
                    <th scope="col" style="text-align:left;"><?php _e(\'Quantity\', \'woothemes\'); ?></th>
                    <th scope="col" style="text-align:left;"><?php _e(\'Price\', \'woothemes\'); ?></th>
                </tr>
            </thead>
            <tfoot> 
                <tr>
                    <th scope="row" colspan="2" style="text-align:left; padding-top: 12px;"><?php _e(\'Subtotal:\', \'woothemes\'); ?></th>
                    <td style="text-align:left; padding-top: 12px;"><?php echo $order->get_subtotal_to_display(); ?></td>
                </tr>
                <?php if ($order->order_shipping > 0) : ?><tr>
                    <th scope="row" colspan="2" style="text-align:left;"><?php _e(\'Shipping:\', \'woothemes\'); ?></th>
                    <td style="text-align:left;"><?php echo $order->get_shipping_to_display(); ?></td>
                </tr><?php endif; ?>
                <?php if ($order->order_discount > 0) : ?><tr>
                    <th scope="row" colspan="2" style="text-align:left;"><?php _e(\'Discount:\', \'woothemes\'); ?></th>
                    <td style="text-align:left;"><?php echo woocommerce_price($order->order_discount); ?></td>
                </tr><?php endif; ?>
                <?php if ($order->get_total_tax() > 0) : ?><tr>
                    <th scope="row" colspan="2" style="text-align:left;"><?php _e(\'Tax:\', \'woothemes\'); ?></th>
                    <td style="text-align:left;"><?php echo woocommerce_price($order->get_total_tax()); ?></td>
                </tr><?php endif; ?>
                <tr>
                    <th scope="row" colspan="2" style="text-align:left;"><?php _e(\'Total:\', \'woothemes\'); ?></th>
                    <td style="text-align:left;"><?php echo woocommerce_price($order->order_total); ?> <?php _e(\'- via\', \'woothemes\'); ?> <?php echo ucwords($order->payment_method); ?></td>
                </tr>
            </tfoot>
            <tbody>
                <?php echo $order->email_order_items_table(); ?>
            </tbody>
        </table>

        <h2><?php _e(\'Customer details\', \'woothemes\'); ?></h2>

        <?php if ($order->billing_email) : ?>
            <p><strong><?php _e(\'Email:\', \'woothemes\'); ?></strong> <?php echo $order->billing_email; ?></p>
        <?php endif; ?>
        <?php if ($order->billing_phone) : ?>
            <p><strong><?php _e(\'Tel:\', \'woothemes\'); ?></strong> <?php echo $order->billing_phone; ?></p>
        <?php endif; ?>

        <div style="float:left; width: 49%;">

            <h3><?php _e(\'Billing address\', \'woothemes\'); ?></h3>

            <p>
                <?php echo $order->get_formatted_billing_address(); ?>
            </p>

        </div>

        <div style="float:right; width: 49%;">

            <h3><?php _e(\'Shipping address\', \'woothemes\'); ?></h3>

            <p>
                <?php echo $order->get_formatted_shipping_address(); ?>
            </p>

        </div>

        <div style="clear:both;"></div>

        </article>
    <?php endwhile; ?>
    </section>
    </body>
    </html>
我希望你们能帮助我!

1 个回复
最合适的回答,由SO网友:Scriptonomy 整理而成

以下是解决方案:

删除SKU表格标题添加(SKU) 至产品标题Product (SKU)false, true 在里面email_order_items_table 作用$order->email_order_items_table(false, true)这不是您所期望的视觉效果,但它工作正常,并显示SKU。中的第二个参数email_order_items_table 指示是否显示SKU。

相关推荐

如何在WordPress unctions.php中将短代码值传递到Head

我正在尝试为wordpress帖子上的图表创建一个快捷代码。到目前为止,我已经使用了短代码,我可以看到短代码值正在被传递,但我需要知道的是如何将这些值传递到Google图表,以便正确工作。以下是我目前掌握的代码:function chart_shortcode($atts) { $a = shortcode_atts( array( \'value1\' => \'\', \'value2\' => \'\', \'value