在woocommerce中分组产品父母与Grouped产品儿童

问题描述 投票:1回答:1

我正在使用PDF包装插件(WooCommerce PDF Invoices)在下订单后创建装箱单。和Product Bundles插件捆绑产品。

在那些PDF中,我想区分捆绑产品的容器和它的子容器。

目前我在产品包中使用它:

if(wc_pb_is_bundle_container_cart_item($item) )

它检查项目是否是捆绑产品的容器然后返回true。我需要一个类似的函数,如果item是child或者在bundle中,它将返回true。

这是包装单pdf正文的代码:

<?php
/**
 * PDF packing slip template body.
 *
 * This template can be overridden by copying it to youruploadsfolder/woocommerce-pdf-invoices/templates/packing-slip/simple/yourtemplatename/body.php.
 *
 * HOWEVER, on occasion WooCommerce PDF Invoices will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @author  Bas Elbers
 * @package WooCommerce_PDF_Invoices/Templates
 * @version 0.0.1
 */

$templater                      = WPI()->templater();
$order                          = $templater->order;
$formatted_shipping_address     = $order->get_formatted_shipping_address();
$formatted_billing_address      = $order->get_formatted_billing_address();
$line_items                     = $order->get_items( 'line_item' );
$color                          = $templater->get_option( 'bewpi_color_theme' );
?>

<table>
    <tr class="title">
        <td colspan="3">
            <h2><?php _e( 'Packing Slip', 'woocommerce-pdf-invoices' ); ?></h2>
        </td>
    </tr>
    <tr class="information">
        <td width="50%">
            <?php echo nl2br( $templater->get_option( 'bewpi_company_address' ) ); ?>
        </td>

        <td>
            <?php
            if ( $templater->get_option( 'bewpi_show_ship_to' ) && ! empty( $formatted_shipping_address ) && $formatted_shipping_address !== $formatted_billing_address && ! $templater->has_only_virtual_products( $line_items ) ) {
                printf( '<strong>%s</strong><br />', __( 'Ship to:', 'woocommerce-pdf-invoices' ) );
                echo $formatted_shipping_address;
            }
            ?>
        </td>

        <td>
            <?php echo $formatted_billing_address; ?>
        </td>
    </tr>
</table>
<table>
    <thead>
        <tr class="heading" bgcolor="<?php echo $color; ?>;">
            <th>
                <?php _e( 'Qty', 'woocommerce-pdf-invoices' ); ?>
            </th>

            <th>
                <?php _e( 'Product', 'woocommerce-pdf-invoices' ); ?>
            </th>

            <th>

                <?php _e( 'SKU', 'woocommerce-pdf-invoices' ); ?>
            </th>
        </tr>
    </thead>
    <tbody>
    <?php
    //$parentItem = 0;
    foreach ( $line_items as $item_id => $item ) { 

        $product = BEWPI_WC_Order_Compatibility::get_product( $order, $item );


        if(wc_pb_is_bundle_container_cart_item($item)  ){
        ?>

        <tr class="item">
            <td width="10%">
                <?php  echo $item['qty']; ?>
                <?php // print_r($item); die(); ?>
            </td>

            <td width="65%">
                <?php
                echo $item['name'];

                do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order );

                $templater->wc_display_item_meta( $item, true );
                $templater->wc_display_item_downloads( $item, true );

                do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order );
                ?>
            </td>

            <td width="25%">

                <?php echo $product && $product->get_sku() ? $product->get_sku() : '-'; ?>
            </td>
        </tr>

    <?php  }  else   { ?>
        <tr class="item">
            <td width="10%" style="float:right;">
                <?php  echo $item['qty']; ?>
            </td>

            <td width="5%" style="float:right;">
                <?php
                echo '----'.$item['name'];
                //echo 'i m child';

                do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order );

                $templater->wc_display_item_meta( $item, true );
                $templater->wc_display_item_downloads( $item, true );

                do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order );
                ?>
            </td>

            <td width="25%" style="float:right;">

                <?php echo $product && $product->get_sku() ? $product->get_sku() : '-'; ?>
            </td>
        </tr>


        <?php }} ?>
    </tbody>
</table>

<table class="notes">
    <tr>
        <td>
            <?php
            // Customer notes.
            if ( $templater->get_option( 'bewpi_show_customer_notes' ) ) {
                // Note added by customer.
                $customer_note = BEWPI_WC_Order_Compatibility::get_customer_note( $order );
                if ( $customer_note ) {
                    printf( '<strong>' . __( 'Note from customer: %s', 'woocommerce-pdf-invoices' ) . '</strong><br />', nl2br( $customer_note ) );
                }

                // Notes added by administrator on 'Edit Order' page.
                foreach ( $order->get_customer_order_notes() as $custom_order_note ) {
                    printf( '<strong>' . __( 'Note to customer: %s', 'woocommerce-pdf-invoices' ) . '</strong><br />', nl2br( $custom_order_note->comment_content ) );
                }
            }
            ?>
        </td>
    </tr>
</table>

只有当产品是任何产品包的一部分时,我才想在产品名称前附加qazxsw poi。只是想要这个检查,我无法弄清楚我该怎么做

谢谢。

php wordpress woocommerce
1个回答
1
投票

问题是你使用----而不是Cart Functions

首先,当我们检查订单商品时,您需要使用Order Functions而不是wc_pb_is_bundle_container_order_item

此外,wc_pb_is_bundle_container_cart_item是您应该用来确定产品是否是容器项目的子项目的检查。这很重要,因为它会检查项目是否具有父容器,因此当您还按顺序排列非捆绑项目时,您的代码也可以扩展。

以下是问题的部分相关代码。

wc_pb_is_bundled_order_item
© www.soinside.com 2019 - 2024. All rights reserved.