感谢阅读,刚刚有关于WooCommerce的问题,我想在下面的结算字段中添加一个简短的说明结帐页面 .
如何在以下结算字段的WooCommerce结帐页面添加简短说明?
我尝试添加功能,自定义代码但失败并出现错误 .
add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_so_27900033', 10, 2 );
function wc_checkout_description_so_27900033( $other_data, $cart_item )
{
$post_data = get_post( $cart_item['product_id'] );
$other_data[] = array( 'name' => 'description', 'value' => $post_data->post_excerpt );
return $other_data;
}
我使用了这段代码,但它显示的是内部产品信息表 .
1 回答
没有理由打电话给
get_post()
.$product
对象存储在$cart_item
数组中,$post
对象存储在$product
内 . 由于woocommerce_get_item_data
过滤器出现的唯一位置在购物车类中,因此可能会在订单接收页面或我的帐户区域或电子邮件等中显示产品's excerpt (aka the short description) to show up in the cart and in the checkout. Now, it isn' t .需要注意的一点是,WooCommerce 2.7是对WooCommerce的重大改写,
$_product->post->post_excerpt
将导致PHP通知直接访问产品属性 . 所以我建议使用2.6和2.7兼容的方法 .