【发布时间】:2018-12-03 23:15:21
【问题描述】:
我希望这是一个愚蠢的问题,但我目前找不到聪明的解决方案。
我的产品页面中有一个自定义字段 - 这是一个关系字段 - 我想为我的购物车页面中的每个产品显示我的 RF 字段。
更具体地说:我有一个与品牌相关的产品。该品牌有一个“运输时间”字段。
目前我的功能部分工作,从某种意义上说,它显示请求值,但仅适用于购物车中的第一项。 这是我在function.php中的代码
add_filter( 'woocommerce_get_item_data', 'wc_add_shipping_to_cart', 10, 2 );
function wc_add_shipping_to_cart( $cart_data, $cart_item )
{
$custom_shipping = array();
if( !empty( $cart_data ) )
$custom_shipping = $cart_data;
// Get the product ID
$product_id = $cart_item['product_id'];
$custom_field_value = get_post_meta( $product_id, 'brand_select', true );
$display_brand_shipping = get_field('shipping_time_brand', $custom_field_value);
if( $custom_field_value = get_post_meta( $product_id, 'brand_select', true ) )
$custom_shipping[] = array(
'name' => __( 'Shipping', 'woocommerce' ),
'value' => $display_brand_shipping,
'display' => $display_brand_shipping,
);
return $custom_shipping; }
你能帮我吗?
【问题讨论】:
-
产品与品牌的关系如何?品牌是自定义分类法还是产品属性?这个品牌的分类是什么?是否为产品设置了品牌(就像产品类别或产品标签一样)?
-
'brand' 是自定义帖子类型,我通过关系字段将产品与其关联
-
抱歉,我帮不上忙,因为它太习惯了,无法猜测什么不起作用。
-
呃,您需要什么样的信息?我有一个名为“品牌”的 cpt,其中有一些字段(运输时间、网站等)。我有一些产品通过关系字段与品牌相关联。鉴于这种关系,我想在购物车页面上显示相关品牌的字段
标签: woocommerce advanced-custom-fields