问题描述
我正在使用带有woocommerce_before_order_itemMeta
的钩子,以在模板的functions.PHP上获取订单元数据中的分类和当前产品的类别。但这不起作用,这是问题所在:
Fatal error: Uncaught Error: Call to a member function get_items()
中的布尔值上的functions.PHP:402
重要! > 产品是使用WP Fundraising Donation plugin完成的自定义帖子,因此问题在于调用自定义帖子分类法,因为它不同于产品分类法。
// GET TAXONOMY
add_action( 'woocommerce_before_order_itemMeta','get_the_terms_hook',10,3 );
function get_the_terms_hook ( $item_id,$item,$post) {
// Get $product object from $order / $order_id
$order = wc_get_order( $order_id );
$items = $order->get_items(); // this is the line 402
foreach ( $items as $item ) {
$product = wc_get_product( $item['product_id'] );
// Now you have access to (see above)...
$product->get_categories();
$product->get_category_ids();
$product->get_tag_ids();
}
解决方法
如果您要按订单进行流程,谢谢,那么这会对您有所帮助。检查内容以及评论。 Click Here