Mahbubur Rahman

Thoughts and Writings

06 Mar 2017
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

1 Comments
  1. Bablofil March 21, 2017 at 9:44 am

    Thanks, great article.

Leave a Comment

Your email address will not be published. Required fields are marked *