Geo link

<?php add_action( 'woocommerce_before_add_to_cart_button', 'affiliate_link', 10); function affiliate_link() { $not_avilable_country = '<div id="amz_not_avilable" class="amz_not_avilable">This product is not avilable in your country yet</div>'; // IP Geolocation $country_code = $_SERVER ["HTTP_CF_IPCOUNTRY"]; // Get Custom Fields $de_asin = get_post_meta(get_post()->ID, "wccaf_de_asin", true ); $uk_asin = get_post_meta(get_post()->ID, "wccaf_uk_asin", true ); ////////////////////////////////////////////// if ($country_code=="DE" or $country_code=="DE") { $amazon_domain = 'https://www.amazon.de'; // $associate_id = 'bonstato-21'; $asin = $de_asin; } else if ($country_code=="GB" && $uk_asin!=="") { $amazon_domain = 'https://www.amazon.co.uk'; // $associate_id = 'bonmedico-21'; $asin = $uk_asin; } /////////////////////////////////////////////// if( wp_is_mobile() ) { // Amazon Link For Mobile ?> <script> function amzGo(){ window.location='<?php echo $amazon_domain ?>/dp/<?php echo $asin ?>/?tag=<?php echo $associate_id ?>'; } </script> <?php } else { // Amazon Link For PC ?> <script> function amzGo(){ window.location='<?php echo $amazon_domain ?>/gp/aws/cart/add.html?AssociateTag=<?php echo $associate_id ?>&ASIN.1=<?php echo $asin ?>&Quantity.1=1'; } </script> <?php } ?> <div class="buy_amz_btn_wrap" > <button type="button" id="buy_amz_btn" class="buy_amz_btn" onclick="amzGo();"><i class="fa fa-amazon fa-amz"></i><?php echo $amz_btn_title ?></button> </div> <?php } ?>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.