woocommerce offtopic – How to get ACF values to be read in WooCommere email-order-items.php ? (if else not working too)

Question

I have been spending hours modifying the email-order-items.php in my WooCommerce theme. I need to show values m2 and pcs just after qty number in email quantity table based on ACF product option. Here is the code. Only the last if elseif ($per_unit_or_square == 'blank') {} is being printed, which maked me think I have done something wrong there.

I am just self-learning php, so sorry if there is something ridicously wrong in my code (it might be something with so many if elseif’s):

$qty          = $item->get_quantity();
$qty77        = wc_format_decimal($item->get_quantity(), 3 ); // quantity with decimal value
$refunded_qty = $order->get_qty_refunded_for_item( $item_id );

global $post;
global $product;
$order->get_id();
$product = $item->get_product();
$per_unit_or_square = get_field('pricem2_or_priceunit_', $product->get_id());

if (!empty($per_unit_or_square)) {
    if ($per_unit_or_square == 'm2') {
        if ( $refunded_qty ) {
                $qty_display = '<del>' . esc_html( $qty77 ) . '</del> <ins>' . esc_html( $qty77 - ( $refunded_qty * -1 ) ) . '</ins>';
            } else {
                $qty_display = esc_html( $qty77 );  
            }
        echo wp_kses_post( apply_filters( 'woocommerce_email_order_item_quantity', '<span>' . $qty_display. '&nbsp;m<sup>2</sup></span>', $item ) );
        } 
elseif ($per_unit_or_square == 'unit') { 
        if ( $refunded_qty ) {
                $qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * -1 ) ) . '</ins>';
            } else {
                $qty_display = esc_html( $qty );
            }
        echo wp_kses_post( apply_filters( 'woocommerce_email_order_item_quantity', $qty_display, $item ) );
        //echo wp_kses_post( apply_filters( 'woocommerce_email_order_item_quantity', '<span>' . $qty_display. '&nbsp;pcs</span>', $item ) );
        } 
elseif ($per_unit_or_square == 'blank') {
if ( $refunded_qty ) {
                $qty_display = '<del>' . esc_html( $qty ) . '</del> <ins>' . esc_html( $qty - ( $refunded_qty * -1 ) ) . '</ins>';
            } else {
                $qty_display = esc_html( $qty );
            }
        echo wp_kses_post( apply_filters( 'woocommerce_email_order_item_quantity', $qty_display, $item ) );

             }
}

0
twelvell 3 weeks 2021-03-23T16:56:31-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse