Categories
Plugins WP User Frontend

How to create form for uploading external/affiliate type WooCommerce product

The process for creating a form to upload external/affiliate type product given here.

1) Add a hidden type field with meta key & value to your product form. The meta value should be external.

Refer Screenshot:
http://prntscr.com/egkcws

2) Add an URL & a text type custom field, insert _product_url & _button_text meta key for them respectively.

Refer Screenshot:
http://prntscr.com/egkdox

3) Add the following code inside the theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.
function wpuf_support_external_product( $post_id ) {
   
    $product_type = get_post_meta( $post_id, 'product_type', true );

    wp_set_object_terms( $post_id, $product_type, 'product_type' );
   
}

add_action( 'wpuf_add_post_after_insert', 'wpuf_support_external_product' );
add_action( 'wpuf_edit_post_after_update', 'wpuf_support_external_product' );

Now, check the form on the frontend, try to upload a product & check the submitted product type in wp-admin. The product type should be external/affiliate.

Reference Video:
https://www.youtube.com/watch?v=i2NDYqlAqjo

Categories
Plugins WP User Frontend

How to show all the posts submitted by all users in a page

To show all the posts submitted by all users in a page, follow the instructions given here.

1) Create a new page, insert [wpuf_dashboard] shortcode in that page & Publish it.

Refer Screenshot:
http://prntscr.com/egiu0w

2) Add the following code inside the theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.
function show_all_posts_for_admin( $args  ) {

    if ( current_user_can( 'administrator' ) ) {
        unset($args['author']);
        return $args;
    }else {
        return $args;
    }

}

add_filter( 'wpuf_dashboard_query', 'show_all_posts_for_admin' );

Now, logged in from multiple users account & submit posts using frontend form, check the page you created on the frontend. You can see all the posts submitted by all users on that page.

Categories
Plugins WordPress WP User Frontend

How to add user id as product SKU with WP User Frontend product form.

You can follow the instructions given below to insert user id as product SKU.

1) Add a hidden field to the product form you created & insert _sku meta key to that field.

​Refer Screenshot:
http://prntscr.com/ef1e0f

2) Now, Add the following code inside the theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.


function wpuf_update_product_sku( $post_id ) {
   
    if ( isset( $_POST['_sku'] ) ) {

            $user_id = get_current_user_id();
            update_post_meta( $post_id, '_sku', $user_id );

    }

}

add_action( 'wpuf_edit_post_after_update', 'wpuf_update_product_sku' );
add_action( 'wpuf_add_post_after_insert', 'wpuf_update_product_sku' );

​​

​All done, submit a product using frontend product form & check the product SKU in wp-admin. The SKU id will be the user id.

Categories
Plugins WooCommerce WordPress WP User Frontend

How to create unique SKU with WP User Frontend custom field.

The unique SKU of the products is not being set when the products are created. To add unique SKU with products, then follow the instructions given below.

1) Add a custom text field with _sku to the product form.

Screenshot:
http://prntscr.com/eb2ext

2) Add the following code inside the theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.
function wpuf_unique_product_sku_notice( $error ) {
    if ( isset( $_POST['_sku'] ) ) {
        global $wpdb;

        $sku = $_POST['_sku'];

        $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );

        if ( $product_id ) {
            return __( 'SKU is not unique, you must enter unique SKU' );
        }
    }

    return '';
}

add_filter( 'wpuf_update_post_validate', 'wpuf_unique_product_sku_notice' );
add_filter( 'wpuf_add_post_validate', 'wpuf_unique_product_sku_notice' );

3) Now, try to submit a product using the frontend product form. Use an existing SKU related to other product. You will see the following error.

Screenshot:

All done.

Categories
Plugins WordPress WP User Frontend

How to update WooCommerce sale price dates meta using WPUF date fields

If you are having an issue with updating the schedule dates of WooCommerce product using WPUF fields, you can follow the given instructions to solve this issue.

1) Add two date type field to WPUF form that you created to allow users for uploading products.

2) Insert _sale_price_dates_from & _sale_price_dates_to meta keys accordingly for these two fields.

Refer Screenshot:
http://prntscr.com/du6fqj

3) Change the date format of WPUF date field.

Refer Screenshot:
http://prntscr.com/du66dq

4) Now, add the following code inside the theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.
function update_product_schedule_date_meta( $post_id ) {
    $dates_from = get_post_meta( $post_id, '_sale_price_dates_from', true );
    $dates_to = get_post_meta( $post_id, '_sale_price_dates_to', true );

    $dates_from = strtotime($dates_from);
    $dates_to = strtotime($dates_to);

    update_post_meta( $post_id, '_sale_price_dates_from', $dates_from );
    update_post_meta( $post_id, '_sale_price_dates_to', $dates_to );
}

add_action( 'wpuf_add_post_after_insert', 'update_product_schedule_date_meta' );
add_action( 'wpuf_edit_post_after_update', 'update_product_schedule_date_meta' );

All done, add a product from the frontend with the sales price and insert dates for sales from, sales to fields. The fields data will update properly to WooCommerce sale price dates.

Categories
WP User Frontend

How to charge different amount for different post type using WP User Frontend subscription pack

Here is the guideline for charging a different amount for different post types.

1) Navigate to wp-admin > User Frontend > Subscription. Click on Add New Subscription button to add new subscription.

2) Now, You can see the fields to enter the number for each post.

3) If you want to allow only one post type for that pack then enter the number for that post type field, keep value 0 for other post types.

3) Click on “Publish” button to publish that pack.

All done, now users can only submit to that specific post type after purchasing this pack.