你的代码有点过时了,你应该使用
$product->get_id()
因为你的第一个函数是3而不是
$product->id
在
get_post_meta()
功能。
也可以使用
WC_Data
get_meta()
直接从产品对象。
下面是带附加钩住函数的重新访问代码,该函数将有条件地显示
“增值税减免可用”
(不覆盖模板)
review-order.php
)
add_filter( 'woocommerce_get_price_html', 'conditional_price_suffix', 20, 2 );
function conditional_price_suffix( $price, $product ) {
if ( $product->get_meta('disability_exemption') === 'yes')
$price .= ' ' . __('with vat relief');
else
$price .= ' ' . __('inc vat');
return $price;
}
add_filter( 'woocommerce_checkout_cart_item_quantity', 'custom_text_below_checkout_product_title', 20, 3 );
function custom_text_below_checkout_product_title( $quantity_html, $cart_item, $cart_item_key ){
if ( $cart_item['data']->get_meta('disability_exemption') === 'yes' )
$quantity_html .= '<br>' . __('VAT RELIEF AVAILABLE');
return $quantity_html;
}