skip to Main Content

I’m customizing the Better Messages plugin and I need to replace the username with the name of the product and the price of the product. The transition to the chat comes from the button located on the product page. I wrote a code (below) that should do it, but it can’t get the Product_id because I guess it doesn’t remember what id was on the page from which the transition was made. this is just my guess

`public function get_name($user_id) {
$product_id = isset($_GET[‘product_id’]) ? $_GET[‘product_id’] : 0;
$product = wc_get_product($product_id);

if ($product && $product->get_price()) {
    $name = $product->get_name() . ' - ' . wc_price($product->get_price());
} else {
    $name = 'Unknown Product';
}

return $name;

}`


Please signup or login to give your own answer.
Back To Top
Search