Home / Admin / WP Simple Pay: Programmatically Set Custom Field Default Value
Duplicate Snippet

Embed Snippet on Your Site

WP Simple Pay: Programmatically Set Custom Field Default Value

Use metadata as the default value for a payment form's custom field.

Code Preview
php
<?php
/**
 * @link https://library.wpcode.com/snippet/j57zmp2g/
 */
add_filter(
	// Update `123` to match your Form ID.
	// Update `2`to match the custom field ID.
	'simpay_form_123_field_2_default_value',
	/**
	 * @var string $default
	 * @return string
	 */
	function( $default ) {
		// Set the default value to the value of the current page's `_my_custom_field` metadata value.
		return get_post_meta( get_the_ID(), '_my_custom_field', true );
	}
);

Comments

Add a Comment