product_presave

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.

Shop-Script

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 …

Output

$return['result']
bool=false Value which must be returned to notify about an error. Otherwise, a hook handler shoud not return any value.
$return['error']
string Error message.
Shop-Script

Plugin code example

PHP

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