• Resolved David Bee

    (@davidbawiec)


    Hi!

    Loving the plugin. Great work! I’m currently trying to hook into do_action( 'simpay_process_form', $this ); in order to add some meta data into the transaction info sent to Stripe.

    In my functions file I created the following basic code:

    add_action('simpay_process_form', 'bbs_simpay_process_form');
    function bbs_simpay_process_form() {
    	$this->metadata = array("special_order_info" => "6735");
    }

    Unfortunately this throws the following error:
    Fatal error: Uncaught Error: Using $this when not in object context...
    I tried renaming the function to function bbs_simpay_process_form($this) but that doesn’t work as the hook function happens outside of the scope of the object.

    How do you suggest I go about adding this information into the hook/transaction properly?

    Thanks!
    David

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter David Bee

    (@davidbawiec)

    On a side note, I did end up making it work by using the simpay_payment_metadata filter instead. But curious to learn anyway how to make the action hook work should I need this in the future.
    Thanks!

    Plugin Contributor Phil Derksen

    (@pderksen)

    @davidbawiec You had the right action hook to start, but good to know the filter hook works as well.

    In your example, you just need to add a parameter to your function and merge with the existing metadata. Here’s what should work:

    function bbs_simpay_process_form( $payment ) {
    	$payment->metadata = array("special_order_info" => "6735");
    
    	// Add new metadata to existing metadata before processing payment form.
    	$payment->metadata = array_merge( $payment->metadata, $new_metadata );
    }
    add_action('simpay_process_form', 'bbs_simpay_process_form');

    I just added a more generic example to our code snippet library as well.

    https://github.com/moonstonemedia/WP-Simple-Pay-Snippet-Library/blob/master/add-metadata.php

    Thanks,
    Phil

    • This reply was modified 6 years, 11 months ago by Phil Derksen.
    • This reply was modified 6 years, 11 months ago by Phil Derksen.
    • This reply was modified 6 years, 11 months ago by Phil Derksen.

    Dear friends,

    i have today received from wordpress the following message:

    Fatal error: Uncaught Error: Using $this when not in object context in /home/agenceli/public_html/wp-content/themes/itheme2/themify/themify-utils.php:1711 Stack trace: #0 /home/agenceli/public_html/wp-includes/class-wp-hook.php(286): themify_setup_menu_icons(”) #1 /home/agenceli/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #2 /home/agenceli/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /home/agenceli/public_html/wp-settings.php(450): do_action(‘init’) #4 /home/agenceli/public_html/wp-config.php(99): require_once(‘/home/agenceli/…’) #5 /home/agenceli/public_html/wp-load.php(37): require_once(‘/home/agenceli/…’) #6 /home/agenceli/public_html/wp-admin/admin.php(31): require_once(‘/home/agenceli/…’) #7 /home/agenceli/public_html/wp-admin/index.php(10): require_once(‘/home/agenceli/…’) #8 {main} thrown in /home/agenceli/public_html/wp-content/themes/itheme2/themify/themify-utils.php on line 1711

    I am absolutely outside the IT area and have so very limited it skills. Really do not know what it says and what I should do. I can have access to the ftp, I understand it is something related to the theme I use but really do not know what to do. Any advice would be so welcome! Thanks so much,

    Cristina

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Fatal error: Uncaught Error: Using $this when not in object context’ is closed to new replies.