Reputation: 1708
I manage to generate simple Woocommerce product over REST api. I fail to add product content with html code (e.g. table in my case).
The rest api
$api_response = wp_remote_post( $client_domain . '/wp-json/wc/v3/products', array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( $K.':'.$S )
),
'body' => array(
'name' => $product_name, // product title
// 'status' => 'publish', // default: publish
'type' => 'simple',
'categories' => array(
array(
'id' => 22 // each category in a separate array
)
),
'regular_price' => $price, // product regular price
'price' => $price, // current product price
'description' => $allTable, // **** HTML TABLE ... *****
'short_description' => 'tilesim user product',
'visible' => true, // current product price 'images' => [ ['src' => $pimage] ] // array( "src" => $pimage)
'images' => [
[
'src' => $pimage
],
[
'src' => $rimage
]
]
)
The line with commented starts (****) has the variable ($allTable
) that will be displayed as raw html instead of a table:
![beautified html]https://s-ivry.tilesim.co.il/wp-content/uploads/2019/01/woo_product_html.png)
How do I get over this issue and get the table, not the html markup?
Upvotes: 1
Views: 1848
Reputation: 2011
PHP provides the htmlentities function which are used to encode and decode. Kindly check below examples how you can decode the php strings.
$str = '<a href="https://www.w3schools.com">w3schools.com</a>';
echo html_entity_decode($str);
Upvotes: 2