Home Forums WC Vendors Pro Support wcv_save_product hook

NOTICE: We've Moved to a Ticket System for Support

As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system.  This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.

For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.

If you are a WC Vendors Pro customer please open a support ticket here. 

If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.

The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.

https://docs.wcvendors.com/

Thank you to all of our customers!

 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #59683
    Adam
    Participant

    Hi,

    I was wondering if you could help. I may be using the wcv_save_product hook incorrectly… I have registered a custom taxonomy for the product post type, named ‘product_gender’. I have managed to successfully display this in the Pro dashboard product edit page beneath the category selection by calling this custom function from the product-edit.php template:

    function prefix_form_gender( $object_id ) {
    WCVendors_Pro_Form_helper::select2( array(
    ‘post_id’ => $object_id,
    ‘id’ => ‘product_gender[]’,
    ‘class’ => ‘select2’,
    ‘label’ => __(‘Gender’, ‘jotu’),
    ‘show_option_none’ => __(‘Select Gender’, ‘jotu’),
    ‘taxonomy’ => ‘product_gender’,
    ‘capabilities’ => ‘manage_product’,
    ‘taxonomy_args’ => array(
    ‘hide_empty’ => 0,
    )
    )
    );
    }

    http://pastebin.com/kafM3YSc

    All working fine up to this point. I am able to save the selection of the custom taxonomy when editing an already existing product. I have accomplished this with the below:

    add_action( ‘init’, ‘process_tax_save’ );
    function process_tax_save() {
    if( isset( $_POST[‘product_gender’] ) && isset( $_POST[‘post_id’] ) ) {
    $term = $_POST[ ‘product_gender’ ];
    $id = (int) $_POST[‘post_id’];
    wp_set_object_terms( $id, (int)$term[0], ‘product_gender’ );
    }
    }

    http://pastebin.com/5wTLnVM2

    My issue seems to be when creating a brand new product. When creating a new product, I seem unable to save the custom taxonomy. I am using the wcv_save_product hook for this, which as I understand, should run on post save, correct? Below is my code so far for the addition of new products:

    function save_caracteristica( $post_ID ){
    $term = $_POST[ ‘product_gender’ ];
    wp_set_object_terms( (int) $post_ID, (int)$term[0], ‘product_gender’ );
    }
    add_action( ‘wcv_save_product’, ‘save_caracteristica’, 10, 1 );

    http://pastebin.com/5xP38QWb

    I have tried countless variations of this. I have tried using te ‘save_posts’ hook, as well as modifying the priority. After spending a good number of hours on this, searching through the forums etc. I figured you may be able to point me in the right direction? I am thinking I may need to use a different hook, perhaps I am using wcv_save_product incorrectly?

    Please note, this website is being developed locally.

    Thanks,
    James.

    #59882
    Jamie
    Keymaster

    Hello,

    In version 1.4 I’ve added auto save code so that if you prefix your fields with a _wcv_custom_taxonomy. If you can’t wait till 1.4 is out here is example code that works for display and saving on the product edit form.

    https://gist.github.com/digitalchild/128033d2d41f682acd4387b595d4f607

    cheers,

    Jamie.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.