Ensure subscription product description does not exceed 127 characters

This commit is contained in:
Emili Castells Guasch 2023-09-15 15:33:14 +02:00
parent d3a02e79c5
commit a13da931ed
2 changed files with 11 additions and 6 deletions

View file

@ -83,13 +83,10 @@ class CatalogProducts {
*/ */
public function create( string $name, string $description ): Product { public function create( string $name, string $description ): Product {
$data = array( $data = array(
'name' => $name, 'name' => $name,
'description' => $description ?: $name,
); );
if ( $description ) {
$data['description'] = $description;
}
$bearer = $this->bearer->bearer(); $bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/catalogs/products'; $url = trailingslashit( $this->host ) . 'v1/catalogs/products';
$args = array( $args = array(

View file

@ -178,7 +178,15 @@ class SubscriptionsApiHandler {
$data[] = (object) array( $data[] = (object) array(
'op' => 'replace', 'op' => 'replace',
'path' => '/description', 'path' => '/description',
'value' => $product->get_description(), 'value' => substr(
strip_shortcodes(
wp_strip_all_tags(
$product->get_description()
)
),
0,
127
) ?: '',
); );
} }