WooCommerce Opayo Form插件Reference字段自定义显示(订单号-姓氏)配置求助
Solution for Populating Opayo Reference Field (Opayo Form Gateway)
Hey there! I get it—having that Reference field in Opayo formatted as 订单号 - 姓氏 will save your finance team tons of time, and it’s frustrating when the hook you tried didn’t work. The key issue here is that you used a hook designed for Opayo Direct, but you’re using the Opayo Form gateway—they have separate filter hooks.
Here’s the corrected code you need to use, tailored specifically for Opayo Form:
add_filter( 'opayo_form_custom_field_vendordata', 'my_opayo_form_custom_reference', 10, 2 ); function my_opayo_form_custom_reference( $vendor_data, $order ) { // Retrieve order number and billing last name from the WooCommerce order object $order_number = $order->get_order_number(); $billing_last_name = $order->get_billing_last_name(); // Only set the Reference if both values are present to avoid empty entries if ( ! empty( $order_number ) && ! empty( $billing_last_name ) ) { $vendor_data['Reference'] = $order_number . ' - ' . $billing_last_name; } return $vendor_data; }
Why your original code didn’t work:
- The hook
opayo_direct_custom_field_vendordatais exclusive to the Opayo Direct gateway. Since you’re using Opayo Form, this filter never gets triggered. - The Form gateway uses its own dedicated filter:
opayo_form_custom_field_vendordata—this is the one we’re targeting in the corrected code.
Important Notes:
- Add this code safely: Always use a child theme’s
functions.phpfile, or a code snippets plugin (like Code Snippets) to avoid losing changes when your parent theme updates. - Test with real (or test) orders: Place a test order to confirm the Reference field in Opayo now shows the correct
订单号 - 姓氏format. Make sure the order has a billing last name filled in—we added a check to skip empty values. - Check plugin version: Ensure you’re running the latest version of the Opayo WooCommerce plugin, as older versions might not support this filter or have different hook names.
内容的提问来源于stack exchange,提问作者Alex
相关产品推荐
相关产品推荐

