Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在商业订单编辑页面中显示产品发货类别_Php_Wordpress_Woocommerce_Shipping_Orders - Fatal编程技术网

Php 在商业订单编辑页面中显示产品发货类别

Php 在商业订单编辑页面中显示产品发货类别,php,wordpress,woocommerce,shipping,orders,Php,Wordpress,Woocommerce,Shipping,Orders,我使用的函数允许我根据每个产品的装运类别计算购物车中的多个运费。功能没有问题,非常完美。但是,当我在woocommerce管理领域检查请求时,我需要在提交方法中确定每个项目对应的类的名称 也就是说,我需要区分每个类别的商品,因为我使用shipping类别来通知不同的供应商在商店下的订单 但我不知道如何进行这种调整 下面是我使用的函数,基于创建的类处理包。此函数负责根据装运类别计算购物车中的运费。如何在store admin中的订单页面上显示发货类名称 function custom_sp

我使用的函数允许我根据每个产品的装运类别计算购物车中的多个运费。功能没有问题,非常完美。但是,当我在woocommerce管理领域检查请求时,我需要在提交方法中确定每个项目对应的类的名称

也就是说,我需要区分每个类别的商品,因为我使用shipping类别来通知不同的供应商在商店下的订单

但我不知道如何进行这种调整

下面是我使用的函数,基于创建的类处理包。此函数负责根据装运类别计算购物车中的运费。如何在store admin中的订单页面上显示发货类名称

    function custom_split_shipping_packages_shipping_class( $packages ) {
    // Reset all packages
    $packages              = array();
    $regular_package_items = array();
    $split_package_items   = array();
    $split_shipping_class = 'da-vinci'; // Shipping class slug
    foreach ( WC()->cart->get_cart() as $item_key => $item ) {
        if ( $item['data']->needs_shipping() ) {
            if ( $split_shipping_class == $item['data']->get_shipping_class() ) {
                $split_package_items[ $item_key ] = $item;
            } else {
                $regular_package_items[ $item_key ] = $item;
            }
        }
    }
    // Create shipping packages
    if ( $regular_package_items ) {
        $packages[] = array(
            'contents'        => $regular_package_items,
            'contents_cost'   => array_sum( wp_list_pluck( $regular_package_items, 'line_total' ) ),
            'applied_coupons' => WC()->cart->get_applied_coupons(),
            'user'            => array(
                 'ID' => get_current_user_id(),
            ),
            'destination'    => array(
                'country'    => WC()->customer->get_shipping_country(),
                'state'      => WC()->customer->get_shipping_state(),
                'postcode'   => WC()->customer->get_shipping_postcode(),
                'city'       => WC()->customer->get_shipping_city(),
                'address'    => WC()->customer->get_shipping_address(),
                'address_2'  => WC()->customer->get_shipping_address_2()
            )
        );
    }
    if ( $split_package_items ) {
        $packages[] = array(
            'contents'        => $split_package_items,
            'contents_cost'   => array_sum( wp_list_pluck( $split_package_items, 'line_total' ) ),
            'applied_coupons' => WC()->cart->get_applied_coupons(),
            'user'            => array(
                 'ID' => get_current_user_id(),
            ),
            'destination'    => array(
                'country'    => WC()->customer->get_shipping_country(),
                'state'      => WC()->customer->get_shipping_state(),
                'postcode'   => WC()->customer->get_shipping_postcode(),
                'city'       => WC()->customer->get_shipping_city(),
                'address'    => WC()->customer->get_shipping_address(),
                'address_2'  => WC()->customer->get_shipping_address_2()
            )
        );
    }
    return $packages;
}
add_filter( 'woocommerce_cart_shipping_packages', 'custom_split_shipping_packages_shipping_class' );

我还不知道如何在订单发货项目中显示发货类。但我可以通过以下方式显示此装运类别以编辑“行\项”:

// Display the shipping classes names in Order edit line items
add_action( 'woocommerce_after_order_itemmeta', 'custom_admin_order_itemmeta', 15, 3 );
function custom_admin_order_itemmeta( $item_id, $item, $product ){
    if( ! is_admin() ) return; // only backend

    // Display the shipping class names if they exist
    if( $item->is_type( 'line_item' ) ){
        $label = __( 'Shipping class:', 'woocommerce' );
        $class_id = $product->get_shipping_class_id();
        if( $class_id > 0 ){
            $term = get_term_by( 'id', $class_id, 'product_shipping_class' );
            $class_name = esc_html($term->name);
        }
        if( isset($class_name) )
            echo '<div class="wc-order-item-ship-class"><strong>' . $label . '</strong> <span style="color:#ca4a1f;">' . $class_name . '</span></div>';
    }
}
//以编辑行项目的顺序显示装运类别名称
添加动作('woocommerce'在'u order'u itemmeta'之后,'custom'u admin'u order'u itemmeta',15,3);
函数自定义\管理\订单\项目元($item\u id,$item,$product){
如果(!is_admin())返回;//仅后端
//显示装运类别名称(如果存在)
如果($item->is_类型('line_item')){
$label=_uuuu('Shipping class:','woocommerce');
$class_id=$product->get_shipping_class_id();
如果($class_id>0){
$term=获取条件('id',$class\u id,'product\u shipping\u class');
$class\u name=esc\u html($term->name);
}
if(isset($class_name))
回显“”.$label.“.$class_name.”;
}
}
代码位于活动子主题(或活动主题)的function.php文件或任何插件文件中

测试和工作。您将得到如下结果:

注意:在Woocommerce 3.2.x上,我在签出时遇到了一个错误,与您的实际代码有关