Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi Neil,

    Looks like there were a couple errors due to copy-pasting some code. I’ve updated the Gist now if you want to try the new version.

    You’ll probably need to do some further wrangling depending on your needs. When I tested just now, the fax field appeared at the bottom and with an odd icon.

    Thread Starter neilgee

    (@neilgee)

    Great – works now – so I’ll have a go at it!

    Thread Starter neilgee

    (@neilgee)

    I got it to work and included my store and mobile fields – question I have now is how can i move my mobile number field to be after the main number field.

    I tried to alter it via the shortcodes but the mobile gets output last

    https://gist.github.com/neilgee/19859a58e6b24f25c604

    Hi Neil,

    You’ll need to rebuild the array with the order of callbacks that you want. That will look something like this (untested);

    function hcbp_component_callbacks( $callbacks ) {
    	global $bpfwp_controller;
    	if ( $bpfwp_controller->settings->get_setting( 'mobile' ) ) {
    		$new_callbacks = array();
    		foreach( $callbacks as $key => $val ) {
    			$new_callbacks[$key] = $val;
    
    			// When you find the element you want to place it after,
    			// slot it in.
    			if ( $key == 'phone' ) {
    				$callbacks['mobile'] = 'hcbp_print_mobile';
    			}
    		}
    
    		$callbacks = $new_callbacks;
    	}
    	return $callbacks;
    }
    add_filter( 'bpwfwp_component_callbacks', 'hcbp_component_callbacks' );

    Beware that if no phone value exists the mobile field will never be added. A more sophisticated way to do this is to use array_slice().

    Thread Starter neilgee

    (@neilgee)

    Hi Nate – thanks for the snippet, I replaced the existing hcbp_component_callbacks function with it but it doesn’t output the new field in any place.

    Hi Neil,

    I haven’t tested the code at all so you’ll need to pick through to find the problem. Are you comfortable debugging PHP code?

    You’ll probably want to add some logging details to each conditional to see where the code is ending early.

    Thread Starter neilgee

    (@neilgee)

    Hi Nate,

    I tried with array_splice not not much success there (probably my skill level more than anything).

    I looked at your code again, if I var dump your $callbacks I can see the key and value for the new mobile pair but it’s sitting on the end of the array.

    I tried to recreate the array in the order I want and return that but eventhough the order is now correct it is displaying the email and map fields even when I have them not appearing, so this is not the right approach.

    I see the typo in my code. The line where it adds the mobile callback:

    $callbacks['mobile'] = 'hcbp_print_mobile';

    Is wrong. It should add it to the NEW array:

    $new_callbacks['mobile'] = 'hcbp_print_mobile';
    Thread Starter neilgee

    (@neilgee)

    Yes that’s it working great now – many thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Add Cell Number’ is closed to new replies.