【发布时间】:2020-02-28 17:51:59
【问题描述】:
我的产品页面上有一个“自定义字段”,我想在 Woocommerce 购物车页面中的产品标题上方添加它。
这是自定义字段数据:
我用这个 PHP 代码让它在单个产品卡上工作
add_action( 'woocommerce_after_shop_loop_item_title', 'product_card_beschrijving', 2);
function product_card_beschrijving(){
global $product;
$beschrijving = get_post_meta( $product->id, 'product_card_beschrijving', true );
if ( ! empty( $beschrijving ) ) {
echo '<span class="beschrijving">' . $beschrijving . '</span>';
}
}
我已经为购物车页面尝试了相同的代码,但对其进行了一些修改,但未加载自定义字段的元数据。我用过$get_item_data 等等,但无法正常工作
<p class="cart-subtitel">
<?php $beschrijving = get_post_meta( $product->id, 'product_card_beschrijving', true ); echo '<span class="beschrijving">' . $beschrijving . '</span>'?>
</p>
【问题讨论】:
标签: php wordpress woocommerce