mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Remove shortcodes from description
This commit is contained in:
parent
43a5b759f2
commit
7e16b39bbb
2 changed files with 24 additions and 17 deletions
|
@ -58,7 +58,7 @@ class ItemFactory {
|
||||||
mb_substr( $product->get_name(), 0, 127 ),
|
mb_substr( $product->get_name(), 0, 127 ),
|
||||||
new Money( $price, $this->currency ),
|
new Money( $price, $this->currency ),
|
||||||
$quantity,
|
$quantity,
|
||||||
substr( wp_strip_all_tags( $product->get_description() ), 0, 127 ) ?: '',
|
$this->prepare_description( $product->get_description() ),
|
||||||
null,
|
null,
|
||||||
$product->get_sku(),
|
$product->get_sku(),
|
||||||
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
||||||
|
@ -130,7 +130,7 @@ class ItemFactory {
|
||||||
mb_substr( $item->get_name(), 0, 127 ),
|
mb_substr( $item->get_name(), 0, 127 ),
|
||||||
new Money( $price_without_tax_rounded, $currency ),
|
new Money( $price_without_tax_rounded, $currency ),
|
||||||
$quantity,
|
$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,
|
null,
|
||||||
$product instanceof WC_Product ? $product->get_sku() : '',
|
$product instanceof WC_Product ? $product->get_sku() : '',
|
||||||
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
|
||||||
|
@ -198,4 +198,15 @@ class ItemFactory {
|
||||||
$category
|
$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')
|
->expects('get_cart_contents')
|
||||||
->andReturn($items);
|
->andReturn($items);
|
||||||
|
|
||||||
expect('wp_strip_all_tags')
|
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||||
->with('description')
|
expect('strip_shortcodes')->andReturnFirstArg();
|
||||||
->andReturn('description');
|
|
||||||
|
|
||||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||||
$session = Mockery::mock(\WC_Session::class);
|
$session = Mockery::mock(\WC_Session::class);
|
||||||
|
@ -99,9 +98,8 @@ class ItemFactoryTest extends TestCase
|
||||||
->expects('get_cart_contents')
|
->expects('get_cart_contents')
|
||||||
->andReturn($items);
|
->andReturn($items);
|
||||||
|
|
||||||
expect('wp_strip_all_tags')
|
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||||
->with('description')
|
expect('strip_shortcodes')->andReturnFirstArg();
|
||||||
->andReturn('description');
|
|
||||||
|
|
||||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||||
$session = Mockery::mock(\WC_Session::class);
|
$session = Mockery::mock(\WC_Session::class);
|
||||||
|
@ -130,9 +128,9 @@ class ItemFactoryTest extends TestCase
|
||||||
$product
|
$product
|
||||||
->expects('is_virtual')
|
->expects('is_virtual')
|
||||||
->andReturn(false);
|
->andReturn(false);
|
||||||
expect('wp_strip_all_tags')
|
|
||||||
->with('description')
|
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||||
->andReturn('description');
|
expect('strip_shortcodes')->andReturnFirstArg();
|
||||||
|
|
||||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||||
$item
|
$item
|
||||||
|
@ -190,9 +188,8 @@ class ItemFactoryTest extends TestCase
|
||||||
->expects('is_virtual')
|
->expects('is_virtual')
|
||||||
->andReturn(true);
|
->andReturn(true);
|
||||||
|
|
||||||
expect('wp_strip_all_tags')
|
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||||
->with('description')
|
expect('strip_shortcodes')->andReturnFirstArg();
|
||||||
->andReturn('description');
|
|
||||||
|
|
||||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||||
$item
|
$item
|
||||||
|
@ -245,9 +242,8 @@ class ItemFactoryTest extends TestCase
|
||||||
->expects('is_virtual')
|
->expects('is_virtual')
|
||||||
->andReturn(true);
|
->andReturn(true);
|
||||||
|
|
||||||
expect('wp_strip_all_tags')
|
expect('wp_strip_all_tags')->andReturnFirstArg();
|
||||||
->with($description)
|
expect('strip_shortcodes')->andReturnFirstArg();
|
||||||
->andReturn(mb_substr( $description, 0, 127 ));
|
|
||||||
|
|
||||||
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
$item = Mockery::mock(\WC_Order_Item_Product::class);
|
||||||
$item
|
$item
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue