php 将自定义字段添加到Popup Maker MailChimp集成表单。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 将自定义字段添加到Popup Maker MailChimp集成表单。相关的知识,希望对你有一定的参考价值。

<?php

// Only copy below this line.
// -------------------------------------------------------------


/**
 * Register a custom attribute or more. This is useful to limit where your custom fields appear.
 */
add_filter( 'pum_sub_form_shortcode_defaults', 'custom_pum_mc_shortcode_atts' );
function custom_pum_mc_shortcode_atts( $defaults ) {
	$defaults['custom1'] = '';
	return $defaults;
}

/**
 * Process any extra submitted fields and add the needed data to the api subscriber request.
 */
add_filter( 'pum_mailchimp_sub_list_args', 'process_custom_pum_mc_fields' );
function process_custom_pum_mc_fields( $subscriber ) {
	if ( isset( $_POST['custom1'] ) ) {
		$subscriber['merge_fields']['CUSTOM1'] = sanitize_text_field( $_POST['custom1'] );
	}

	return $subscriber;
}

/**
 * Render any custom fields when the custom1 attr exists.
 */
add_action( 'pum_newsletter_fields', 'custom_pum_mc_fields' );
function custom_pum_mc_fields( $atts ) {

	if ( ! empty( $atts['custom1'] ) ) {

		?>

		<div class="pum-form__field  pum-sub-form-field">
			<label class="pum-form__label  pum-sub-form-label">Custom 1
			<input type="text" name="custom1" placeholder="Custom 1">
			</label>
		</div>

		<?php
	}
}

以上是关于php 将自定义字段添加到Popup Maker MailChimp集成表单。的主要内容,如果未能解决你的问题,请参考以下文章

php 将自定义字段添加到购物车/结帐

php 将自定义字段添加到ACF对象选择

php 将自定义字段添加到WooCommerce产品变体

php 将自定义字段(按顺序)添加到电子邮件中

php 将自定义字段(按顺序)添加到电子邮件中

php 将自定义字段(按顺序)添加到电子邮件中