php [MarketPress] - 过滤地址字段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [MarketPress] - 过滤地址字段相关的知识,希望对你有一定的参考价值。

<?php
/**
* Plugin Name: [MarketPress] - Filter address fields
* Plugin URI: https://premium.wpmudev.org/
* Description: Filter profile fields to add placeholders, remove laels etc. This can be used as a guide
* Author: Panos Lyrakis @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/

add_filter( 'mp_checkout/address_fields_array', function( $address_fields, $type ) {

	$elements_names_placeholders = array( 
		'billing[first_name]' => 'Insert your first name',
		'billing[last_name]' => 'Insert your last name',
		'billing[email]' => 'Insert your email'
	);

	if( is_array( $address_fields ) ) {

		foreach( $address_fields as $field_key => $address_field ) {

			if( isset( $address_field[ 'subfields' ] ) ) {

				if( ! is_array( $address_field[ 'subfields' ] ) ){
					continue;
				}

				foreach ( $address_field[ 'subfields' ] as $sub_key => $sub_field ) {
					
					if( isset( $sub_field['name'] ) && isset( $elements_names_placeholders[ $sub_field['name'] ] ) ){
						$address_fields[ $field_key ]['subfields'][ $sub_key ]['atts']['placeholder'] = $elements_names_placeholders[ $sub_field['name'] ];
						$address_fields[ $field_key ]['subfields'][ $sub_key ]['label'] = '';
					}

				}

			}
			else{
				if( isset( $address_field['name'] ) && isset( $elements_names_placeholders[ $address_field['name'] ] ) ){
					$address_fields[ $field_key ]['atts']['placeholder'] = $elements_names_placeholders[ $address_field['name'] ];
					$address_fields[ $field_key ]['label'] = '';
				}
			}

		}
		
	}

	return $address_fields;

}, 10, 2 );

以上是关于php [MarketPress] - 过滤地址字段的主要内容,如果未能解决你的问题,请参考以下文章

php [MarketPress] - 预览订单通知

php [MarketPress] - 结帐自定义字段

php [MarketPress] - 出口订单

php [MarketPress] - 重复产品

php [MarketPress - Upfront] - 产品搜索

php 强制MarketPress变化模态100%宽度