好的,基本上我们在 WooCommerce 商店中使用 ACF 创建了一个自定义字段,以便为特定产品添加“发货延迟”通知。
以下是我们所取得成果的演示:https ://www.safe-company.com/shop/machines/uvc-disinfection-lamp/
然后,我们设法使用 Elementor(页面构建器)将此通知放入单个产品页面中,然后将此信息添加到购物车和结帐页面中的商品数据中,并将以下代码添加到我们的functions.php中
// Render the custom product field in cart and checkout
add_filter( 'woocommerce_get_item_data', 'wc_add_shipping_delay', 10, 2 );
function wc_add_shipping_delay( $cart_data, $cart_item )
{
$custom_items = array();
if( !empty( $cart_data ) )
$custom_items = $cart_data;
// Get the product ID
$product_id = $cart_item['product_id'];
if( $custom_field_value = get_post_meta( $product_id, 'shipping_delay_for_out_of_stock_items', true ) )
$custom_items[] = array(
'name' => __( 'Shipping Delay', 'woocommerce' ),
'value' => $custom_field_value,
'display' => $custom_field_value,
);
return $custom_items;
}
我们现在的问题是,我们需要将此运送延迟通知添加到电子邮件中(分别显示在包含此数据的每个项目下方)以及订单页面上。怎么可能呢?因为我已经检查了很多关于此的线程,但所有这些线程都是使用动态字段(用户在购买时完成)完成的,但我们的案例场景完全不同。
小怪兽爱吃肉
显示 WooCommerce 自定义产品属性和单个产品的所有术语
使特定产品在 WooCommerce 中互斥
允许客户在 WooCommerce 中更改订单状态
在 Woocommerce 订单页面中,创建与订单 ID 相关的自定义文本字段