I have set the price suffix for all my products in Woocommerce (“per box” in my case). This works for variable products as well as for single products without problems.
Now I want this prefix to change to “per pallet” for some product variations of a product. I’ve read a lot and tried a lot, but I haven’t found a solution yet that could be applied to individual variants of a product. Can anyone help me?
Below is the Code I tried. There are no error messages, but it does not change the price of a specific id.
add_filter('woocommerce_available_variation', 'variation_price_custom_suffix', 10, 3 );
function variation_price_custom_suffix( $variation_data, $product, $variation ) {
$args = array(
'post_parent' => get_the_ID() // get parent post-ID
);
$variations = get_posts( $args );
foreach ( $variations as $variation ) {
// get variation ID
$variation_ID = $variation->ID;
// get variation price
$variation_price = $product_variation->get_price_html();
get_post_meta( $variation_ID , '_text_field_date_expire', true );
}
if($variation_ID == 732) {
$variation_data['price_html'] .= "Text after price";
}
return $variation_data;
}
Many thanks in advance and many greetings keved