• Resolved Vincent Poirier

    (@magikweb)


    Hey!

    We’ve been using this plugin for a while now and it’s been working great. On our old Website we used to have a Simple Pay form that used the old shortcode and the amount attribute to set the price. We used to set the price like this because we needed it to be dynamic and change according to get variables. On our new website, we’re trying to to something similar but the shortcode has changed and it’s no longer possible to use the amount attribute.

    We tried adding a form with a fixed amount and then adding this code to our functions.php:

    add_filter( 'simpay_form_4021_amount', 'simpay_custom_amount' );
    function simpay_custom_amount() {
    	return 4000;
    }

    Unfortunately it doesn’t seem to work. Could you tell us what’s wrong with our code or tell us if there is a better way to get a dynamic price. The ID is correct and the return value is like this for testing purpose. It will be a variable later

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Adam Lea

    (@adamjlea)

    Hello Vincent,

    I tested the above code with the latest version of the plugin and it worked as expected. See screenshots below.

    Code added: https://take.ms/KMbnY
    $1.00 set in admin: https://take.ms/H3J5F
    $400 on Stripe Checkout: https://take.ms/aOjt3
    Successful transaction: https://take.ms/0OTy6
    Transaction in Stripe: https://take.ms/Z4QXu

    I would double check the form ID, which I’m sure you’ve done, one more time. Perhaps check for plugin or other conflicts. The code appears to work as expected.

    Regards,

    Thread Starter Vincent Poirier

    (@magikweb)

    Something was wrong with my theme actually and the amount worked, but I have a similar bit of code that does not work as expected. I tried to to the same with the item description but it does not seem to work. I added an item description “asdf” using the SimplePay form editor in the backend and when I do this:

    add_filter( 'simpay_form_4021_item_description', 'simpay_custom_description', 1 );
    function simpay_custom_description($item_description) {
    	$item_description = "Test description";
    	return $item_description;
    }

    The item description doesn’t change and it still displays “asdf”. I know that the filter is triggered because I tried simply doing this:

    add_filter( 'simpay_form_4021_item_description', 'simpay_custom_description', 1 );
    function simpay_custom_description($item_description) {
    	var_dump($item_description);
    	return $item_description;
    }

    And the default description I added in the WordPress dashboard prints on screen. So the event does trigger, but returning a new description doesn’t seem to work for some reason

    Plugin Contributor Adam Lea

    (@adamjlea)

    Hey Vincent,

    It works on the frontend form and purchase confirmation but doesn’t get carried over to the description in Stripe because we aren’t filtering the meta call.

    A temporary fix is to filter the meta call:

    add_filter( 'simpay_form_50_item_description', function() {
    	return 'custom description';
    } );
    
    add_filter( 'get_post_metadata', function( $value, $form_id, $meta_key ) {
    	if ( 50 === $form_id && '_item_description' === $meta_key ) {
    		return 'custom description';
    	}
    
    	return $value;
    }, 10, 3 );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dynamic pricing’ is closed to new replies.