Collect personalization information in Marketplace

I'm creating a website for an author who wants to offer autographed copies of his book. I want to collect the name of the person he should write the inscription to. How can I collect that information?

  • James Morris

    Hello Sj,

    I hope you are well today.

    I'm afraid it's not possible with the current version of MarketPress to add custom fields out of the box. Something like that would take custom development.

    However, if you don't mind re-purposing the "Company" checkout field, there's a solution. You can use the following custom code as a Must Use plugin (mu-plugin) to collect this data and store is at the company name field.

    <?php
    
    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',
    		'billing[company_name]' => 'Insert your desired inscription'
    	);
    
    	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 );

    Just save that code as a php file and upload it to your wp-content/mu-plugins/ folder and it will update the address form on checkout. See screenshot: https://i.imgur.com/1iLukA1.png

    Let us know if you have any further questions. We'll be happy to help! :slight_smile:

    Best regards,

    James Morris

  • James Morris

    Hello Sj,

    After speaking with one of our Senior SLS Techs ( Panos ) , he's provided an excellent MU plugin that will accomplish exactly what you're wanting to do.

    Please see the code at the following link: https://gist.github.com/wpmudev-sls/2ec264489c6919669d725c7d53bc23d0

    You will need to update the code to match your exact needs of course, but this should do quite nicely.

    Best regards,

    James Morris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.