BuddyDev

Search

[Resolved] 3 Product for Pay Per Post

  • Participant
    Level: Initiated
    Posts: 6
    Lode on #50345

    Hi,

    i installed Pay Per Post Add-on. This is working fine. But know i had a question about the pricing.

    I would like to let customers add 3 types : BLOG, NEWS and ANNOUNCEMENTS.

    1. the blog they can add for 4,95€
    2. the news for 9.95€
    3. the announcement for 19.95€

    I made 3 products in Woocommerce and selected as an product option – connected to the form.

    The problem is, when a customer write an announcement and he chooses the “blog for 4,95€” he can publish the announcement for 4,95€ instead than for 19,95€.

    How i can prevent users can publish the most expensive chose for the lowest price?

    Regards, Lode

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2985
    Ravi on #50353

    Hello Lode,

    I am assuming your are using dropdown view of category which allow only one category to be selected. Try the following code:

    
    add_filter( 'bblpro_validation_errors', function ( $errors, $data, $prepared_post_data, $form_id ) {
    
    	if ( ! function_exists( 'bbl_ppp_form_has_paid_posting_enabled' ) || ! bbl_ppp_form_has_paid_posting_enabled( $form_id ) ) {
    		return $errors;
    	}
    
    	if ( is_wp_error( $errors ) && $errors->has_errors() ) {
    		return $errors;
    	}
    
    	// Do not validate if save draft action.
    	if ( isset( $data['action'] ) && 'bblpro_save_draft' == $data['action'] ) {
    		return $errors;
    	}
    
    	// Replace with your taxonomy.
    	$tax                 = 'category';
    	$taxonomy            = get_taxonomy( $tax );
    	$term_data           = isset( $data['tax_input'] ) ? wp_unslash( $data['tax_input'] ) : array();
    	$selected_term       = isset( $term_data[ $tax ] ) ? absint( current( $term_data[ $tax ] ) ) : 0;
    	$selected_product_id = isset( $data['bblpro_ppp_product_id'] ) ? absint( $data['bblpro_ppp_product_id'] ) : 0;
    
    	if ( empty( $selected_product_id ) || empty( $selected_term ) ) {
    		return $errors;
    	}
    
    	/**
    	 * array (
    	 *    product_id => category_id
    	 * )
    	 */
    	$product_category_mapped_ids = array(
    		5 => 16,
    		6 => 18,
    	);
    
    	if ( ! isset( $product_category_mapped_ids[ $selected_product_id ] ) ) {
    		// what should we need to return here. If selected product not in mapped array.
    		return $errors;
    	}
    
    	if ( $product_category_mapped_ids[ $selected_product_id ] != $selected_term ) {
    		$errors->add( "bbl_tax_$tax", sprintf( __( '%s is invalid. Please select matched with selected product', 'buddyblog-pro' ), $taxonomy->labels->singular_name ) );
    	}
    
    	return $errors;
    }, 20, 4 );
    
    

    Note: Please replace taxonomy and mapped product and term id array as per your configuration. Please give it a try. Please make sure the product and category field is required.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 6
    Lode on #50358

    Sorry Ravi, that’s not clear. Where do i have to put this code? I don’t understand your proposal. Regards, Lode

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2985
    Ravi on #50360

    Hello Lode,

    I am assuming BLOG, NEWS and ANNOUNCEMENTS are the categories and in the following code, I am mapping WooCommerce products with these categories so that at the time of form submission I can make sure that the Category and selected WooCommerce products are similar.

    
    
    /**
    	 * array (
    	 *    product_id => category_id
    	 * )
    	 */
    	$product_category_mapped_ids = array(
    		5 => 16,
    		6 => 18,
    	);
    
    

    If this is not the case. Please let me know what are BLOG, NEWS and ANNOUNCEMENTS.

    You can put the code in the ‘bp-custom.php’ file. If you do not know what is bp-custom file you can refer to the following blog post:

    https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/

    Regards
    Ravi

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 6
    Lode on #50372

    Ok Ravi you can close it. It’s to complicated. I think the plugin is made to add just ONE type of content to ONE FORM and ONE PRODUCT/PRICE? I don’t understand why there is the possibility to link several products/prices to one form nut online ONE content type to ONE FORM…

    This was my idea :
    1. 3 forms (one for blog content, one for news content, one for announcement content)
    2. I connect the “blog product/price” to the blog form, the “news product/price” to the news form and the same for announcement.
    3. after my member write the content they can chose the “category” to put it in
    4. probmlem is – I can only link a POST TYPE to ONE FORM

    You can only connect ONE POST TYPE to ONE POST FORM.

    Why is it possible to connect SEVERAL products to ONE form?

    Is my idea possible? If not – no problem, i configurated for the moment only for the news because it is most relevant.

    Many thx for your effort to help me out of my scatterbrain.
    Lode

You must be logged in to reply to this topic.

This topic is: resolved