In WooCommerce, I have added a "subscribe" button in single product pages. It opens a popup window from an URL like:
https://elfromulario.com?sku=
where I add the product SKU as an URL variable.
But when I use it, the browsers block the pop-up window.
Is there a more functional way or a more efficient way to do it?
My code:
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_custom_content', 25 );
function woocommerce_template_custom_content(){
global $product;
$sku = $product->get_sku();
if (isset($_POST['subscriberc'])) {
// Redirect to with the SKU appended
$googleUrl = "https:https://googleurl.com/Formulario.php?SKU=" . $sku;
echo '<script>window.open("' . $googleUrl . '");</script>';
}
?><form method="post">
<input type="hidden" name="subscriberc" value="1">
<input style="
background: #034392 !important;
font-family: 'Open Sans', sans-serif;
font-size: 15px;
font-weight: bold;
width: 200px;
margin-bottom: 18px;
" type="submit" value="¡SUSCRIBITE AHORA!">
</form><?
}