Actions and Filters

Actions and Filters

Filters


If you have your own PNO or Org number field and want to use that instead of the one that is provided with the plugin, you can do this by using the filter payer_pno_field_name.

Example code: 

add_filter( 'payer_pno_field_name', 'pb2b_change_pno_field' );
/**
 * Example code for changing the PNO field used for Payer B2B.
 *
 * @param string $field_name The name of the field.
 * @return string
 */
function pb2b_change_pno_field( $field_name ) {
	$field_name = 'my-field-name';
	return $field_name;
}

If you want to add a reference to the invoice you can use the following example code.

add_filter( 'payer_update_order_args', 'pb2b_add_invoice_reference', 10, 2 );
/**
 * Example code for adding an invoice reference to a Payer B2B order.
 *
 * @param array $request_args The Payer B2B create order request args.
 * @param int   $order_id The WooCommerce order ID.
 * @return array
 */
function pb2b_add_invoice_reference( $request_args, $order_id ) {
	// Decode the body first.
	$body = json_decode( $request_args['body'], true );
	// Add your reference value.
	$body['invoiceCustomer']['address']['yourReference'] = '12345'; // For example get_post_meta( $order_id, 'your_reference_field_name' );
	// Enqueue the body again.
	$body = json_encode( $body );
	// Add the body back to the request args.
	$request_args['body'] = $body;
	// Return the request args.
	return $request_args;
}