I used chatgpt to create a shortcode to get the product name of a WooCommerce product by id, this is what I got:
function get_woocommerce_product_name_by_id($atts) {
// Extract the attributes from the shortcode
$atts = shortcode_atts(array(
‘id’ => ”,
), $atts);
if (empty($atts[‘id’])) {
return ‘Please provide a product ID.’;
}
$product = wc_get_product($atts[‘id’]);
if (!$product) {
return ‘Product not found.’;
}
return $product->get_name();
}
add_shortcode(‘product_name’, ‘get_woocommerce_product_name_by_id’);
​
Could someone please tell me if the code is safe? does it have something that could break my site?
Thanks!
[ad_2]