在 WooCommerce上添加演示网站

默认将代码加入到主题function文件内,如果不起作用,就添加到插件woocommerce/includes/wc-template-functions.php
/**
* 在WooCommerce加入购物车按钮后添加查看演示代码
*/
function isa_before_add_to_cart_form() {
global $post;
$demoslug = $post->post_name;
$domain = ‘domain.com’;
// put the new url together
if (is_ssl()) {
$protocol = ‘https’;
} else {
$protocol = ‘http’;
}
//$demourl = $protocol . ‘://’ . $demoslug . ‘.’ . $domain;
$demourl = $protocol . ‘://’ . $demoslug . ‘.wptang.com’ ;
$demotitle = esc_attr($post->post_title);
echo ‘<a href=”‘.$demourl.’” title=”‘.$demotitle.’” id=”livedemo” class=”button” target=”_blank”>Live Demo</a>’;
}
add_action(‘woocommerce_after_add_to_cart_button’,’isa_before_add_to_cart_form’);
以上代码在主题function里。另外在自定义css里添加
#livedemo { margin-left:8px; }
来源:https://isabelcastillo.com/demo-button-single-product-woocommerce

发表评论

电子邮件地址不会被公开。 必填项已用*标注