Php woocommerce结帐页=”的;“内部服务器错误”;
我重新安装了 WoodPress 5.3+woocommerce 3.8.1+woocommerce店面主题 然后我用这个代码来计算每个产品的重量Php woocommerce结帐页=”的;“内部服务器错误”;,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我重新安装了 WoodPress 5.3+woocommerce 3.8.1+woocommerce店面主题 然后我用这个代码来计算每个产品的重量 // Display the cart item weight in cart and checkout pages add_filter( 'woocommerce_get_item_data', 'display_custom_item_data', 10, 2 ); function display_custom_item_data(
// Display the cart item weight in cart and checkout pages
add_filter( 'woocommerce_get_item_data', 'display_custom_item_data', 10, 2 );
function display_custom_item_data( $cart_item_data, $cart_item ) {
if ( $cart_item['data']->get_weight() > 0 ){
$cart_item_data[] = array(
'name' => __( 'Weight subtotal', 'woocommerce' ),
'value' => ( $cart_item['quantity'] * $cart_item['data']->get_weight() ) . ' ' . get_option('woocommerce_weight_unit')
);
}
return $cart_item_data;
}
// Save and Display the order item weight (everywhere)
add_action( 'woocommerce_checkout_create_order_line_item', 'display_order_item_data', 20, 4 );
function display_order_item_data( $item, $cart_item_key, $values, $order ) {
if ( $values['data']->get_weight() > 0 ){
$item->update_meta_data( __( 'Weight subtotal', 'woocommerce' ), ( $cart_item['quantity'] * $cart_item['data']->get_weight() ) . ' ' . get_option('woocommerce_weight_unit') );
}
}
一切都能完美运行。在我点击chekout页面中的“下单”之前,我会看到“内部服务器错误”
你知道如何修复这个错误吗
我放了一个调试日志(也许它会帮助您了解发生了什么)
将第二个函数的代码替换为以下代码以解决问题
// Save and Display the order item weight (everywhere)
add_action( 'woocommerce_checkout_create_order_line_item', 'display_order_item_data', 20, 4 );
function display_order_item_data( $item, $cart_item_key, $values, $order ) {
if ( $values['data']->get_weight() > 0 ){
$item->update_meta_data( __( 'Weight subtotal', 'woocommerce' ), ( $item['quantity'] * $values['data']->get_weight() ) . ' ' . get_option('woocommerce_weight_unit') );
}
}
在函数中没有传递的变量像$cart\u item。非常有效!现在我明白了为什么它没有通过。非常感谢你的帮助
// Save and Display the order item weight (everywhere)
add_action( 'woocommerce_checkout_create_order_line_item', 'display_order_item_data', 20, 4 );
function display_order_item_data( $item, $cart_item_key, $values, $order ) {
if ( $values['data']->get_weight() > 0 ){
$item->update_meta_data( __( 'Weight subtotal', 'woocommerce' ), ( $item['quantity'] * $values['data']->get_weight() ) . ' ' . get_option('woocommerce_weight_unit') );
}
}