• Resolved jdowns1

    (@jdowns1)


    Hi. I’m needing to create campaigns via PHP code as part of my automated script. What is the format expected to pass for the list of suggested_donations and suggested_donations_default? This is what I have but the suggested_donations values are not being set in the campaign.

    		$args = array(
    
    		'title' => $campaignName,
    		'creator' => 1,
    		'status' => 'publish',
    		'comment_status' => false,
    		'parent' => 0,
    		'suggested_donations' => array(10,25,50,100,250,500,1000),
    		'suggested_donations_default' => 25,
    		'allow_custom_donations' => true,
    		'minimum_donation_amount' => 20,
    	);
    			
    	$campaign = charitable_create_campaign( $args );
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WPCharitable

    (@wpcharitable)

    @jdowns1 thanks for reaching out.

    So the below function should show what you pass through (which if you look in the post meta for a campaign where you have a suggestion donation(s) and default, you’ll see the serialized versions of these).

        $args = array(
            'title' => 'Test Campaign',
            'suggested_donations' => array( array(
                'amount' => 5,
                'description' => 'gold'
            ) ),
            'suggested_donation_amount' => array (
                '$5.00'
            ),
            'allow_custom_donations' => 1,
        );

    For more background information, you can check out the files charitable/includes/campaigns/class-charitable-campaign-processor.php. I hope this helps. Let me know if you have further questions.

    Thread Starter jdowns1

    (@jdowns1)

    This is perfect, thank you. I did look at class-charitable-campaign-processor.php but couldn’t tell what the array should look like from that.

    Thread Starter jdowns1

    (@jdowns1)

    I’m creating campaigns via PHP, setting allow_custom_donations to 0 (see below), and when I view the campaigns in the UI, they are always created with allow_custom_donations as enabled/checked/true.

    $args = array(
    
    		'title' => 'my campaign',
    
    		'creator' => 1,
    		'status' => 'publish',
    
    		'parent' => 0,
    
    		'suggested_donations' => array( 
    			array(
                'amount' => 20
                //'description' => ''
    			),
    			array(
                'amount' => 35
    			),
    			array(
                'amount' => 50
    			),
    			array(
                'amount' => 100
    			),
    			array(
                'amount' => 250
    			),
    			array(
                'amount' => 500
    			),
    			array(
                'amount' => 1000
    			)
    		),
    
    		'allow_custom_donations' => 0,
    	);
    
    			
    	$campaign_id = charitable_create_campaign( $args );
    Plugin Author WPCharitable

    (@wpcharitable)

    @jdowns1 Upon initial inspection (just checking quickly with your code) I can confirm what you see. For now, i’m going to send this to our developer team to confirm and (if this is a bug) apply a fix for the next release.

    Meantime you can add this after the code and it should force the option to be 0 (unchecked), as I confirmed.

    update_post_meta( $campaign_id, '_campaign_allow_custom_donations', '0' );

    I’m going to go ahead and close this ticket but I’ll update this when the release containing the bug (or if another explanation is discovered). Thanks!

    Plugin Author WPCharitable

    (@wpcharitable)

    @jdowns1 Just an update. We will be pushing out a potential fix for this in 1.8.0 which is going to be released soon. Just need to make sure to pass the value as a string like:

    ‘allow_custom_donations’ => ‘0’,
    or
    ‘allow_custom_donations’ => ‘1’

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Create campaigns via code’ is closed to new replies.