All Topics
ACF Column Value
Hi,
after updating plugin to latest version my custom code to add some calculated value on acf column not work in “product variation”
I have add this code:
function add_product_margini_content( $value, $id, AC\Column $column ) {
if ( is_admin() ) {
// Check for the ACF column
if ( $column instanceof ACA\ACF\Column ) {
$meta_key = $column->get_meta_key();
$meta_type = $column->get_post_type();
if ('cc_etichetta_margine' === $meta_key) {
// Get product object
$product = wc_get_product( $id );
$fields = get_post_meta ($id);
$costo = get_post_meta( $id, '_wc_cog_cost', true );
$marginemin = get_field('cc_etichetta_margine');
$standardprice = $product->get_price();
if (('product' === $column->get_post_type()) && ($product->is_type( 'variable' ))) {
$prezzomin = 0;
}else {
$prezzomin = ($costo*($marginemin/100))+$costo;
}
/*//$prezzomin = ($costo*($marginemin/100))+$costo;
if (is_array ($marginemin)){
$prezzomin = '';
} else {
$prezzomin = ($costo*($marginemin/100))+$costo;
}*/
//$value.= $costo."</br>".$marginemin."</br>".$standardprice."</br>".$prezzomin;
if (!empty($marginemin)){
//Verde
if (($prezzomin>0) && ($standardprice>$prezzomin)){
$value .= "</br><span style='font-size:12px; background: #90da8a;padding: 2px;border-radius: 2px;border: 1px solid #c3cac2;'>P.S. | <span style='padding: 5px;color: #fff;font-weight: 600;'>".number_format($prezzomin,2)." </span></span><hr>";
}
//Rosso
elseif (($prezzomin>0) && ($standardprice<$prezzomin)) {
$value .= "</br><span style='font-size:12px; background: #f26666; padding: 2px;border-radius: 2px;border: 1px solid #c3cac2;'>P.S. | <span style='padding: 5px;color: #fff; font-weight: 600;'>".number_format($prezzomin,2)." </span></span><hr>";
}
//Arancione
elseif (($prezzomin>0) && ($standardprice=$prezzomin)) {
$value .= "</br><span style='font-size:12px; background: #ff9933; padding: 2px;border-radius: 2px;border: 1px solid #c3cac2;'>P.S. | <span style='padding: 5px;color: #fff; font-weight: 600;'>".number_format($prezzomin,2)." </span></span><hr>";
}
}
}
}
return $value;
}
}
add_filter( 'ac/column/value', 'add_product_margini_content', 10, 3 );
that add some div after acf field “$marginemin = get_field(‘cc_etichetta_margine’);”
But the div is printed only in Product column and not in product variation column.
How can i fix please ?
Thanks
You must be logged in to reply to this topic.