I am modifying my shop to show custom fields on WooCommerce order page after the order has been made.
My code is inserted into default /themes/mytheme/woocommerce/order/order-details-item.php
. This is the part that reads the field:
$per_unit_or_square = get_field('pricem2_or_priceunit_', $product->get_id());
if (!empty($per_unit_or_square)) {
if ($per_unit_or_square == 'unit') {
$pricingtype_order_received = '<span class="pricingtype_order_received">'.__(' unit ', 'mbb').'</span>';
} elseif ($per_unit_or_square == 'm2') {
$pricingtype_order_received = '<span class="pricingtype_order_received">'.__(' m<sup>2</sup> ', 'mbb').'</span>';
} else {
$pricingtype_order_received = '<span class="pricingtype_order_received">'.__(' pcs ', 'mbb').'</span>';
}
}
As you can see above, I am trying to set a variable $pricingtype_order_received
and put it here just after the quantity numebers to show if the customer bought units, m2 or pcs:
if ( $refunded_qty ) {
$qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * -1 ) ) . '</ins>'.$pricingtype_order_received;
} else {
$qty_display = esc_html( $qty ).$pricingtype_order_received;
}
My issue is that the code does not work and not retrieving $pricingtype_order_received
value. The same logic worked on cart and other pages, but not working on orders, and in email after the order have been made.
Where to look for? Does ACF fields can be read on order and email?
Here is the whole code if someone interested: https://pastebin.com/PCDs32LC
Try to replace $product->get_id()
with $item->get_product_id()
like:
$per_unit_or_square = get_field( 'pricem2_or_priceunit_', $item->get_product_id() );
Related: Get Order items and WC_Order_Item_Product in WooCommerce 3