Upgraded to WordPress 6.0 and have issues? Please check the hotfix which you need to apply.

Okay
  Public Ticket #3002758
add automatic price 0 to any new product
Closed

Comments

  •  1
    thomas started the conversation

    hi there,

    could you provide me with a functions.php snippet that sets up the price to 0 whenever i add a new product. that would be very convenient, thanks!

    thomas

  •  1
    thomas replied

    ok i go this one, here is the functions.php code for anyone interested:

    /**
     * Sets the product default price 0. Only works once, if the price is not specified.
     */
    function set_product_default_price( $post_id, $post ) {
        $product     = wc_get_product( $post_id );
        $already_set = get_post_meta( $post_id, '_set_default_price', true );
        $price       = $product->get_price();     if ( 'yes' !== $already_set && empty( $price ) ) {
            $product->set_regular_price( '0' );
            $product->save();         update_post_meta( $post_id, '_set_default_price', 'yes' );
        }
    }
    add_action( 'woocommerce_process_product_meta', 'set_product_default_price', 999, 2 );

    please close this ticket
    thanks

  •  228
    Milingona replied

    Thanks for the feedback. Very glad you managed to solve the issue.


    Milingona Support

    Follow on     Envato     Facebook     Twitter