I am trying to display a suffix text for the price entered via a custom meta field and output via a shortcode.
Here is my code:
function prefix_suffix_price_html($price){
$shortcode = do_shortcode('[shortcode]') ;
$psPrice = '';
$psPrice .= $price;
$psPrice .= '<span class="suffix">'. $shortcode . '</span>';
return $psPrice;
}
add_filter('woocommerce_get_price_html', 'prefix_suffix_price_html');
add_filter( 'woocommerce_cart_item_price', 'prefix_suffix_price_html' );
This works fine on the product and archive pages.
However, it does not work for cart items. The an empty span tag is returned without the content of the shortcode.
2
Answers
I now have omitted the shortcode and solved it for the shopping cart items like this:
This post has helped me further: Get product custom field values as variables in WooCommerce
If in your shortcode function code contain
global $product;
, then the following revisited code should work:Otherwise, you will need to provide in your question the function code for your shortcode, to be able to give you a correct working answer…