mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Merge pull request #1226 from woocommerce/PCP-1482-remove-shortcode
Remove shortcodes from description
This commit is contained in:
commit
1b27a27313
2 changed files with 24 additions and 17 deletions
|
@ -58,7 +58,7 @@ class ItemFactory {
|
|||
mb_substr( $product->get_name(), 0, 127 ),
|
||||
new Money( $price, $this->currency ),
|
||||
$quantity,
|
||||
substr( wp_strip_all_tags( $product->get_description() ), 0, 127 ) ?: '',
|
||||
$this->prepare_description( $product->get_description() ),
|
||||
null,
|
||||
$product->get_sku(),
|
||||
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
||||
|
@ -130,7 +130,7 @@ class ItemFactory {
|
|||
mb_substr( $item->get_name(), 0, 127 ),
|
||||
new Money( $price_without_tax_rounded, $currency ),
|
||||
$quantity,
|
||||
substr( wp_strip_all_tags( $product instanceof WC_Product ? $product->get_description() : '' ), 0, 127 ) ?: '',
|
||||
$product instanceof WC_Product ? $this->prepare_description( $product->get_description() ) : '',
|
||||
null,
|
||||
$product instanceof WC_Product ? $product->get_sku() : '',
|
||||
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
||||
|
@ -198,4 +198,15 @@ class ItemFactory {
|
|||
$category
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanups the description and prepares it for sending to PayPal.
|
||||
*
|
||||
* @param string $description Item description.
|
||||
* @return string
|
||||
*/
|
||||
protected function prepare_description( string $description ): string {
|
||||
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
|
||||
return substr( $description, 0, 127 ) ?: '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,9 +43,8 @@ class ItemFactoryTest extends TestCase
|
|||
->expects('get_cart_contents')
|
||||
->andReturn($items);
|
||||
|
||||
expect('wp_strip_all_tags')
|
||||
->with('description')
|
||||
->andReturn('description');
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
$session = Mockery::mock(\WC_Session::class);
|
||||
|
@ -99,9 +98,8 @@ class ItemFactoryTest extends TestCase
|
|||
->expects('get_cart_contents')
|
||||
->andReturn($items);
|
||||
|
||||
expect('wp_strip_all_tags')
|
||||
->with('description')
|
||||
->andReturn('description');
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
$session = Mockery::mock(\WC_Session::class);
|
||||
|
@ -130,9 +128,9 @@ class ItemFactoryTest extends TestCase
|
|||
$product
|
||||
->expects('is_virtual')
|
||||
->andReturn(false);
|
||||
expect('wp_strip_all_tags')
|
||||
->with('description')
|
||||
->andReturn('description');
|
||||
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||
$item
|
||||
|
@ -190,9 +188,8 @@ class ItemFactoryTest extends TestCase
|
|||
->expects('is_virtual')
|
||||
->andReturn(true);
|
||||
|
||||
expect('wp_strip_all_tags')
|
||||
->with('description')
|
||||
->andReturn('description');
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||
$item
|
||||
|
@ -245,9 +242,8 @@ class ItemFactoryTest extends TestCase
|
|||
->expects('is_virtual')
|
||||
->andReturn(true);
|
||||
|
||||
expect('wp_strip_all_tags')
|
||||
->with($description)
|
||||
->andReturn(mb_substr( $description, 0, 127 ));
|
||||
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||
expect('strip_shortcodes')->andReturnFirstArg();
|
||||
|
||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||
$item
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue