Custom Button next to “ADD TO CART” button of WooCommerce based on Product Type



PHP Snippet 1:

function wc_shop_demo_button() {
    echo '<a class="button demo_button" style="padding-right: 0.75em;padding-left: 0.75em;margin-left: 8px; background-color: #0ebc30;" href="'.get_field( "url_demo" ).'" target="_blank">View Demo</a>';
}
add_action( 'woocommerce_after_shop_loop_item', 'wc_shop_demo_button', 20 );
add_action( 'woocommerce_after_add_to_cart_button', 'wc_shop_demo_button', 20 );

PHP Snippet 2:

function wc_shop_demo_button() {
    echo '<a class="button demo_button" href="'.get_field( "url_demo" ).'" target="_blank">View Demo</a>';
}
add_action( 'woocommerce_after_add_to_cart_button', 'wc_shop_demo_button' );

PHP Snippet 3:

the_field('url_demo');

PHP Snippet 4:

 get_field('url_demo');

PHP Snippet 5:

/* Adding demo button to Woocommmerce products */
function wc_shop_demo_button() {
  $product = wc_get_product(get_the_id());
  $url_demo = $product->get_attribute('url_demo');
  echo '<a class="button" href="'.$url_demo.'" target="_blank">View Demo</a>';
}
add_action('woocommerce_after_shop_loop_item', 'wc_shop_demo_button', 20);
add_action('woocommerce_after_add_to_cart_button', 'wc_shop_demo_button', 20);