skip to Main Content

Just wondering if anyone would have the solution to my snippet not working.

I would like to fetch the value of the two custom fields from the order and then update a gravity form entry. I think the issue is in the fetching of the order info.
Please help!

add_action( 'woocommerce_payment_complete','sendtoformentry');
function sendtoformentry($order_id) {
         
    $order = new WC_Order( $order_id );         
    $order_id = $order->get_order_number();   
    $fieldnumber($order_id, 'paymentnumber', true);
    $entrynumber($order_id, 'bookingnumber', true);
    GFAPI::update_entry_field( rgar( $entrynumber, 'id' ), $fieldnumber, 'paid' );
}

2

Answers


  1. add_action('woocommerce_payment_complete', 'sendtoformentry', 10, 2);
    
    function sendtoformentry($order_id, $transaction_id) {
    
        $fieldnumber = get_post_meta($order_id, 'paymentnumber', true);
        $entrynumber = get_post_meta($order_id, 'bookingnumber', true);
        GFAPI::update_entry_field(rgar($entrynumber, 'id'), $fieldnumber, 'paid');
    }
    

    The hook inside woocommerce core is like do_action( 'woocommerce_payment_complete', $this->get_id(), $transaction_id );

    Login or Signup to reply.
  2. You may need to use ‘woocommerce_checkout_order_processed’ instead. Also, try using the GFAPI method below:

    //add order number to gravity forms
    add_action( 'woocommerce_checkout_order_processed', 'sendtoformentry' );
    function sendtoformentry( $order_id ) {
        $fieldnumber = get_post_meta($order_id, 'paymentnumber', true);
        $entrynumber = get_post_meta($order_id, 'bookingnumber', true);
        $entry = GFAPI::get_entry( $entrynumber );
        if(GFAPI::entry_exists( $entry ) && !empty($fieldnumber)){
          $entry[$fieldnumber] = 'paid';
          $result = GFAPI::update_entry( $entry );
        }
        return;        
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search