53
Today I start a personal WooCommerce customization marathon as I try to relaunch my personal project A Piece of Sicily (a Sicilian products marketplace, WPML friendly, with products uploaded by vendors and external (affiliate) products).
Each week I will share a snippet I’ve personally coded, so that you can follow me along the going-live path and actually see the results on the live site.
This time, we’ll talk about External Products, and specifically at how to Open the external add to cart URL in a new tab, so that users stay on your WooCommerce website even after visiting the affiliate link. Enjoy!
PHP Snippet: Open External Product Links Into a New Tab/Window @ WooCommerce Single Product Page
/**
* @snippet Open External New Tab - WooCommerce Single Product
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @compatible WooCommerce 5.1
* @donate $9 https://tutoraspire.com
*/
function woocommerce_external_add_to_cart() {
global $product;
if ( ! $product->add_to_cart_url() ) return;
echo '';
}