wordpress - Open WooCommerce External Products in New Tab -


i'm trying customize woocommerce external product links open in new tabs...

this try:

added filter wordpress theme functions.php file following:

add_filter( 'woocommerce_product_add_to_cart_url', 'woocommerce_externalproducts_openinnewtab' );  function woocommerce_externalproducts_openinnewtab($product_url) {      global $product;      if ( $product->is_type('external') ) {         $product_url = $product->get_product_url() . '"target="_blank""';     }      return $product_url;  } 

what did missed?

what you're doing wrong... get_product_url named do. give url... not html anchor has url, url.. you're adding text url.. that's doing...

one solution given @ash patel. can change markup using templates... navigate plugin folder , file.. woocommerce\templates\single-product\add-to-cart\external.php. can find instructions inside it.

now, sometimes, don't editing templates... if it's minor edits this...

below code way want it... paste code in theme's functions.php.

remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 ); add_action( 'woocommerce_external_add_to_cart', 'rei_external_add_to_cart', 30 ); function rei_external_add_to_cart(){      global $product;      if ( ! $product->add_to_cart_url() ) {         return;     }      $product_url = $product->add_to_cart_url();     $button_text = $product->single_add_to_cart_text();      do_action( 'woocommerce_before_add_to_cart_button' ); ?>     <p class="cart">         <a href="<?php echo esc_url( $product_url ); ?>" target="_blank" rel="nofollow" class="single_add_to_cart_button button alt"><?php echo esc_html( $button_text ); ?></a>     </p>     <?php do_action( 'woocommerce_after_add_to_cart_button' ); } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -