kriot
7/5/2019 - 7:39 PM

Demo Button

<?php
// Add Live Demo Button Next to Cart
function riot_before_single_add_to_cart_button() {
	global $post;
		$demoslug = $post->post_name;
		$demourl = get_bloginfo('url').'/'.$demoslug.'/';
		$demotitle = esc_attr($post->post_title);
	// get just the domain without http
		$home_url = home_url();
		$find = array( 'http://', 'https://', 'http://www.', 'https://www.', 'www.' );
		$domain = str_replace( $find, '', $home_url );
	// put the new url together
	if (is_ssl()) {
			$protocol = 'http';
	} else {
			$protocol = 'http';
	}
	$demourl = $protocol . '://demo.' . $domain . '/' . $demoslug;

	echo '<a href="'.$demourl.'" title="'.$demotitle.'" class="live-demo" target="_blank">Live Demo</a>';
	 }
add_action('woocommerce_before_add_to_cart_button','riot_before_single_add_to_cart_button');