• Resolved adrjan

    (@adrjan)


    Hello together,

    is there a possibility to automatic change the category of an product if it is sold out? For example, if I buy an item with a stock quantity of 1, the product category for this item changes after the checkout process to something else.

    Thank your for any help!

    Greetings
    Adrjan

    https://www.ads-software.com/plugins/woocommerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    There is no existing code, but there is a suitable hook you can use to do the customisation yourself https://github.com/woothemes/woocommerce/blob/f5e9875548a99933be66f07f90ed26ce2c1909f8/includes/abstracts/abstract-wc-product.php#L341

    Thread Starter adrjan

    (@adrjan)

    Thank you Mike.
    But I’am a very beginner, how exactly I can use the hook?
    Can you give me an example how I must modify the code?

    Thank you very much again!

    Thread Starter adrjan

    (@adrjan)

    Ist there an “do_action”-function for changeing the product category?
    And i put this between the if instruction?
    For example?

    if ( update_post_meta( $this->id, '_stock_status', $status ) ) {
    			$this->stock_status = $status;
    			do_action( 'woocommerce_product_set_stock_status', $this->id, $status );
    do_action( 'woocommerce_product_category_change',$this->id, my_category);
    		}

    ?!

    I would be thankful for any help

    Plugin Contributor Mike Jolley

    (@mikejolley)

    woocommerce_product_set_stock_status action is fired on stock change. So you’d:

    1. Hook in a custom function on woocommerce_product_set_stock_status
    2. The hook gives you the product object, so you can check if the new status is out of stock
    3. Then change the category using https://codex.www.ads-software.com/Function_Reference/wp_set_post_terms

    There are plenty of tutorials on using actions and filters if you do a search. If you do need someone to code this up for you, try jobs.wordpress.net

    Thread Starter adrjan

    (@adrjan)

    Thank you Mike!
    I think I can do it somehow.

    Greetings Adrjan

    Hi Adrjan,

    Did you ever figure out how to do this? I have a client who wants exactly the same thing but am not too confident in my ability to set this action properly.

    Would appreciate your sharing your solution.

    Thanks,
    Wizard247

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Automatic change product category after sold out’ is closed to new replies.