• Resolved rizwanbabar693

    (@rizwanbabar693)


    How can I get value of custom field in my function written in functions.php

    function ParsePostRequest($order_id) {
              $order = new WC_Order( $order_id );
    	  foreach ($order->get_items() as $item_id => $item ) {
    	  $item_quantity  = $item->get_quantity(); }
    }

    I have a custom field and I have defined its class as pfid. I want to use its value in function.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support oluisrael

    (@oluisrael)

    Hi @rizwanbabar693

    You can always fetch custom fields value from the order/cart object, but may I know which field needs to be fetched? I mean, is the custom field added from the plugin or another plugin entirely?

    sanderwit

    (@sanderwit)

    I am having a similar issue since the latest update. I used to be able to use this code to retrieve the global field data on the cart page, but no longer.

    add_action( 'woocommerce_before_calculate_totals', 'getcustomfield', 10, 1 );
    function getcustomfield( $cart ) {
        foreach ( $cart->get_cart() as $cart_item ) {
            $customfield = $cart_item['alg_wc_pif_global'][0]['_value'];
        }
    }

    I tried using print_r($cart_item[‘alg_wc_pif_global’]); to find the _value field but it seems to be gone. I also tried using ‘alg_wc_pif_global_1’ and all other variations, but without success. Can anybody help?

    I am having the same issue with the ‘alg_wc_pif_local’ field, since the latest update.

    • This reply was modified 3 years ago by sanderwit.
    Plugin Support oluisrael

    (@oluisrael)

    Hello @sanderwit, I also used the same code that you shared, and I was able to retrieve the input field value correctly, so can you recheck this from your end?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Custom Field Value in code’ is closed to new replies.