BuddyDev

Search

[Resolved] Pay Per Post by selling access with WooCommerce

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43456

    Hello Tosin,

    Thank you for the acknowledgment.

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 196
    Niculae Constantinescu on #43481
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #43510
    This reply has been marked as private.
  • Participant
    Level: Master
    Posts: 196
    Niculae Constantinescu on #43516
    This reply has been marked as private.
  • Participant
    Level: Guru
    Posts: 900
    Tosin on #43586

    Hello

    Please how can I automatically add a post that was paid for to additional category

    e.g
    1. Post A was paid for
    2. After payment is successful
    3. Add submitted post to another category (sponsored post)

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43657

    Hello Tosin,

    Please take a look at the following action:

    
    do_action( 'bblpro_ppp_post_published', $post_id, $form_id );
    
    

    It will fire once the WooCommerce order is completed and after publishing the post.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #43663

    Hello Ravi,

    Please can you take a look at this rough work

    
     function wp_set_post_category( $post_id, $post_categories, $append ) {
        if ( $parent = wp_is_post_revision( $post_id ) )
            $post_id = $parent;
        $post = get_post( $post_id );
        if ( $post->post_type != 'post' )
            return;
        // add a category
        $categories = wp_get_post_category( $post_id );
        $newcat    = get_term_by( 'name', 'Sponsored posts', 'category' );
        array_push( $categories, $newcat->term_id );
        wp_set_post_category( $post_id, $categories );
    }
    do_action( 'bblpro_ppp_post_published', $post_id, $form_id ); 
    

    Thanks

    • This reply was modified 2 years, 9 months ago by Tosin.
  • Participant
    Level: Guru
    Posts: 900
    Tosin on #43666

    or this

     function wp_set_post_categories( $post_id, $post_categories, $append = true ) {
        if ( $post->post_type != 'post' )
            return;
        // add a category
        $categories = wp_get_post_categories( $post_id );
        $newcat    = get_term_by( 'name', 'Sponsored posts', 'category' );
        array_push( $categories, $newcat->term_id );
        wp_set_post_categories( $post_id, $categories );
    }
    do_action( 'bblpro_ppp_post_published', $post_id, $form_id ); 
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #43668

    Hello Tosin,

    Try the following code:

    
    
    add_action( 'bblpro_ppp_post_published', function( $post_id ) {
    	$post_type = get_post_type( $post_id );
    
    	if ( 'post' != $post_type ) {
    		return;
    	}
    
    	// Get category.
    	$newcat = get_term_by( 'name', 'Sponsored posts', 'category' );
    
    	if ( ! $newcat ) {
    		return;
    	}
    
    	wp_set_post_categories( $post_id, $newcat->term_id, true );
    } );
    

    Please check and let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #43672

    Thanks Ravi

    Your code worked perfectly

The topic ‘ [Resolved] Pay Per Post by selling access with WooCommerce’ is closed to new replies.

This topic is: resolved