• Resolved todd.lynch

    (@toddlynch)


    Hi there,

    I have created some custom fields at the checkout process using some code in my functions child theme.
    I have tested them and work fine when I use a direct debit payment method. But we only want to use Paypal express.
    The information is lost/does not get passed when using Paypal express (currently in Sandbox mode).
    Being a total newbie on this, is there some extra coding that needs to be done that I don’t know about? If you could point me in the right direction please?
    Thank you.

    https://www.ads-software.com/plugins/paypal-for-woocommerce/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Contributor angelleye

    (@angelleye)

    When you say it gets lost do you mean it’s not showing up in the WooCommerce order details at all, or do you mean it’s not showing up in the PayPal transaction details, or both?

    Can you provide a snippet of your code that’s adding the custom fields so we can see about reproducing the problem on our test server?

    Thread Starter todd.lynch

    (@toddlynch)

    It doesn’t show in Woocommerce order details, meta or send the info in emails.
    I am also using Order Delivery Date for WooCommerce (Lite version).
    The code below picks out what delivery method the customer is using to send the goods. If it’s a flat rate, then the user must decide whether or not to use authority to leave (ATL). Or if the customer selects local pick up, they must fill in the Order Delivery Date as provided by the above mentioned plugin.

    The code below may be buggy, but I spent countless hours searching for ideas on how to get it right, and it does work when using direct debit as the payment method. The custom code seems to be lost when using Paypal Express.

    You can view it working here (once you have added items to your cart):
    https://newsite.rangeproducts.com.au/cart/

    Here is my code:

    /**
     * Add Authority to Leave select dropdown in checkout page
     **/
    
    add_filter( 'woocommerce_checkout_fields' , 'custom_atl_field');
    
    function custom_atl_field( $fields ) {
    	 $fields['billing']['atl'] = array(
         'type'     => 'select',
         'options'  => array(
         '' => 'Please Select',
         'Yes' => 'Yes',
         'No' => 'No'),
         'label'     => __('Authority to Leave?</br><small style=font-size:10px;font-weight:normal;>If you are having your order delivered, please let us know if we have the authority to leave goods if no one there.</small>', 'woocommerce'),
         'required'  => false,
         'class'     => array('atl form-row-left'),
         'clear'     => true
         );
    
         return $fields;
    }
    
    //ATL question mandatory based on shipping method flat_rate
    add_filter( 'woocommerce_checkout_fields', 'atl_disable' );
    function atl_disable( $atl ) {
        global $woocommerce;
        $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
        $chosen_shipping = $chosen_methods[0];
    
        if( $chosen_shipping == 'flat_rate' ) {
    /**
     * Process the ATL checkout
     */
    add_action('woocommerce_checkout_process', 'my_custom_checkout_atl_process');
    
    function my_custom_checkout_atl_process() {
        // Check if set, if its not set add an error.
        if ( ! $_POST['atl'] )
            wc_add_notice( __( 'You have chosen us to deliver your order. Please answer Authority to Leave question.' ), 'error' );
    	else
    		/**
     * Update the order meta with ATL question
     **/
    add_action( 'woocommerce_checkout_update_order_meta', 'store_atl_update_order_meta' );
    function store_atl_update_order_meta( $order_id ) {
                    if ( $_POST[ 'atl' ] )
                                    update_post_meta( $order_id, 'Authority to Leave', esc_attr( $_POST[ 'atl' ] ) );
    }
    /**
     * Add the ATL custom fields to order emails
     **/
    add_filter('woocommerce_email_order_meta_keys', 'my_atl_checkout_field_order_meta_keys');
    function my_atl_checkout_field_order_meta_keys( $keys ) {
    	$label_name = __("Authority to Leave","atl");
    	$keys[$label_name] = "Authority to Leave";
        return $keys;
    }
    }
    
        }
    
        return $atl;
    
    }
    
    //Pickup question mandatory based on shipping method local_pickup
    add_filter( 'woocommerce_checkout_fields', 'local_pickup_disable' );
    function local_pickup_disable( $local_pickup ) {
        global $woocommerce;
        $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
        $chosen_shipping = $chosen_methods[0];
    
        if( $chosen_shipping == 'local_pickup' ) {
    /**
     * Process the local_pickup checkout
     */
    add_action('woocommerce_checkout_process', 'my_custom_checkout_local_pickup_process');
    
    function my_custom_checkout_local_pickup_process() {
        // Check if set, if its not set add an error.
        if ( ! $_POST['e_deliverydate'] )
            wc_add_notice( __( 'Please let us know when you plan to pick up your order by selecting a collection date.' ), 'error' );
    	else
    		/**
    * Update the order meta with Pick Up question
    **/
    add_action('woocommerce_checkout_update_order_meta', 'my_pickup_field_update_order_meta', 10, 2);
    function my_pickup_field_update_order_meta( $order_id, $posted ) {
        if ( $_POST['e_deliverydate'] ) {
            update_post_meta( $order_id, '_e_deliverydate', esc_attr($_POST['e_deliverydate']));
        }
    }
    /**
     * Add the Pick Up custom fields to order emails
     **/
    add_filter('woocommerce_email_order_meta_keys', 'my_pickup_checkout_field_order_meta_keys');
    function my_pickup_checkout_field_order_meta_keys( $keys ) {
    	$label_name = __("Pick Up Date","e_deliverydate");
    	$keys[$label_name] = "Pick Up Date";
        return $keys;
    }	
    
    }
    
        }
    
        return $local_pickup;
    
    }
    /**
    * Display ATL field value on the order edit page
    **/
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_atl_field_display_admin_order_meta', 10, 1 ); 
    
    function my_atl_field_display_admin_order_meta($order){
    echo '<p><strong>'.__('Authority to Leave').':</strong> ' . get_post_meta( $order->id, 'Authority to Leave', true ). '</p>';
    }
    /**
    * Display Pick Up field value on the order edit page
    **/
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_pickup_field_display_admin_order_meta', 10, 1 ); 
    
    function my_pickup_field_display_admin_order_meta($order){
    echo '<p><strong>'.__('Pick Up Date').':</strong> ' . $order->e_deliverydate. '</p>';
    }
    Plugin Contributor angelleye

    (@angelleye)

    Have you tried using Express Checkout from the WooCommerce checkout page to see if it works as expected then? It could be that the hooks you’re using are only triggered with the WC checkout page, but since Express Checkout skips that page when used from the product or cart pages, those hooks would never be triggered.

    Please set Express Checkout so that it is included in the general list of gateways on your checkout page, and then try checking through that WC checkout page to see if the problem still occurs.

    Thread Starter todd.lynch

    (@toddlynch)

    Sorry I should have already told you that I have done this.
    I didn’t think my code would pass anything unless it was passed from the checkout so have put the Paypal Express checkout in the checkout page only.

    PayPal Express Checkout option:
    Checkout Page Display: Display in general list of enabled gatways on checkout page.

    So to answer your question.

    Express Checkout is set so that it is included in the general list of gateways on my checkout page, and the problem still occurs.

    Any ideas?

    Plugin Contributor angelleye

    (@angelleye)

    I can’t think of anything else off the top of my head. I’ll need to get one of your developers to spend some time working with your custom code to see if they can figure out the issue. In order to do that I would need you to submit an order for premium support.

    If you can track down a specific hook or something that we’re missing we’d be happy to add that to our general list to get fixed, but to study your custom code and troubleshoot what’s going on we’ll need that order.

    Thread Starter todd.lynch

    (@toddlynch)

    OK – so I thought I’d try a little test.

    I completely removed all my custom code.

    Then I installed 5 plugins that enable you to add custom fields at checkout. I enabled them one at a time for each test.

    All plugins passed the direct debit method test.

    The following plugins failed using PayPal:
    Booster for WooCommerce Version 2.2.9
    WooCommerce Checkout Field Editor Version 1.3.1
    Order Delivery Date for WooCommerce (Lite version) Version 1.6
    WooCommerce Checkout Manager Version 3.6.8

    The only plugin that passed both tests was:
    Woocommerce Poor Guys Swiss Knife Version 2.2.4

    Looks like I’ll need to delve into the code a bit more.

    If you have any further thoughts, please let me know.

    Plugin Contributor angelleye

    (@angelleye)

    I’ve added this to our 1.2 list so we’ll look at it more closely then.

    Right now we’re focused on getting our 1.1.6.3.8 list completed, which we hope to have done and released within a week or so. Then we’ll move on to our 1.2 list so it shouldn’t be too terribly long before we’re able to focus on this.

    Thread Starter todd.lynch

    (@toddlynch)

    OK – thank you.

    I have solved my issues by re-writing my code around the Woocommerce Poor Guys Swiss Knife Version 2.2.4 plugin.

    The plugin is much better than all the others in my opinion anyway.

    Plugin Contributor angelleye

    (@angelleye)

    Glad it’s working out for you!

    I’m experiencing the same problem as todd.lynch.

    Using the woocommerce_checkout_update_order_meta hook.

    It saves the data perfectly if I use a different payment gateway, like the COD option.

    Also have Express Checkout enabled as a normal payment gateway.

    Marking it resolved seems a little odd, considering todd had to hack his way around the plugin, but I can start a new topic if that’s appropriate.

    Looks to be exactly the same issue, though.

    Plugin Contributor angelleye

    (@angelleye)

    @nexrmclint, it would probably be best for you to submit a ticket here so we can work directly with you on it. We may need you to provide temporary credentials for your site so we can take a look.

    We gave up on getting it to work and just purchased the Woothemes extension, which works out of the box.

    Thanks!

    Plugin Contributor angelleye

    (@angelleye)

    This has been resolved in the release branch on our GitHub repo. If you’d like to grab it early you can download it here. You’ll need to extract the files and upload them manually to your web server overwriting the existing plugin files.

    The changes will be included in the 1.1.8 update which we’ll be releasing soon.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Custom Fields at Checkout not passing though Paypal Express’ is closed to new replies.