• Resolved mightykyr0

    (@mightykyr0)


    Hi so i have been looking everywhere for this, but cant find anything on it,
    so what i would like to do is prefill product data when a new product is created, i need to do this as i am creating a multi vendor website,
    for example i would like this field id “_credits_amount” to automatically be 1, i have tried using this code

    function wpa104760_default_price( $post_id, $post, $meta_key ) {
    
        if ( isset( $_POST['_regular_price'] ) && trim( $_POST['_regular_price'] ) == '' ) {
            update_post_meta( $post_id, '_credits_amount', '1' );
        }
    
    }
    add_action( 'woocommerce_process_product_meta', 'wpa104760_default_price' );

    but all it does give me an error

    Fatal error: Uncaught ArgumentCountError: Too few arguments to function wpa104760_default_price(), 1 passed in /var/www/bybluerocket.dk/public_html/wp-includes/class-wp-hook.php on line 294 and exactly 3 expected in /var/www/bybluerocket.dk/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()'d code:1 Stack trace: #0 /var/www/bybluerocket.dk/public_html/wp-includes/class-wp-hook.php(294): wpa104760_default_price(741) #1 /var/www/bybluerocket.dk/public_html/wp-includes/class-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array) #2 /var/www/bybluerocket.dk/public_html/wp-includes/plugin.php(484): WP_Hook->do_action(Array) #3 /var/www/bybluerocket.dk/public_html/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-meta-boxes.php(222): do_action('woocommerce_pro...', 741, Object(WP_Post)) #4 /var/www/bybluerocket.dk/public_html/wp-includes/class-wp-hook.php(294): WC_Admin_Meta_Boxes->save_meta_boxes(741, Object(WP_Post)) #5 /var/www/bybluerocket.dk/public_html/wp-includes/class-wp-hook.php(31 in /var/www/bybluerocket.dk/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(469) : eval()'d code on line 1

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prefill product data when adding new product’ is closed to new replies.