Executes custom code before a product gets saved, either manually or during import. A plugin can cancel saving a product by returning an error message in returned array’s 'error' item.


Input (passed by reference)

$params array Parameters.
$params['data'] Array Product data before saving.
$params['dirty'] array Fields which must be updated.
$params['new_data'] array Data to be saved.
$params['instance'] shopProduct Product handling class instance.
… your plugin code …


bool=false Value which must be returned to notify about an error. Otherwise, a hook handler shoud not return any value.
string Error message.

Plugin code example


public function productPresave($params)
    if (!empty($params['new_data']['description']) && strpos($params['new_data']['description'], '#') !== false) {
        return array(
            'result' => false,
            'error' => _wp('# character is not allowed in product descriptions.'),