In woocommerce I have hidden child products in bundles from everywhere, so you can't see them at any point in the process of buying the bundle, but after buying it, they appear in the order with the rest of the info, I want to remove them or hide them everywhere, including the order.
在WooCommerce,我有来自各地的捆绑儿童产品隐藏,所以你在购买捆绑的过程中任何时候都看不到它们,但购买后,它们会与其余信息一起出现在订单中,我想删除它们或将它们隐藏在任何地方,包括订单。
I tried to hide them, but while inside the page, the father product, and the childs are 2 separate class, when it comes to the order, they appear as iqual, so I can't just hide the children because they are all the same product class.
我试着隐藏他们,但在页面中,父亲的产品和孩子是两个独立的类别,当谈到订单时,他们看起来是平凡的,所以我不能只隐藏孩子,因为他们都是同一个产品类别。
更多回答
优秀答案推荐
To hide the child products from the order in WooCommerce, you can use the 'woocommerce_order_item_visible' filter. This filter allows you to control the visibility of items in the order.
要在WooCommerce中的订单中隐藏子产品,可以使用‘WooCommerce_Order_Item_Visible’筛选器。此筛选器允许您控制订单中项目的可见性。
Here is a sample code snippet:
以下是示例代码片段:
add_filter( 'woocommerce_order_item_visible', 'hide_child_products_in_order', 10, 2 );
function hide_child_products_in_order( $visible, $order_item ) {
$product = $order_item->get_product();
if ( $product && $product->is_type( 'simple' ) && $product->get_parent_id() > 0 ) {
// If the product is a child product (i.e., it has a parent), hide it
$visible = false;
}
return $visible;
}
This code checks if the product is a simple product and if it has a parent. If it does, it sets the visibility to false, effectively hiding it from the order.
这段代码检查产品是否是简单产品,以及它是否有父产品。如果是,则将可见性设置为false,有效地将其隐藏在订单中。
Please note that this code is a basic example and might need to be adjusted to fit your specific needs.
请注意,此代码是一个基本示例,可能需要进行调整以适应您的特定需求。
更多回答
我是一名优秀的程序员,十分优秀!