我在WooCommerce的产品页面上具有以下代码的自定义字段
add_action('woocommerce_single_product_summary', 'subtitle_link', 15);
function subtitle_link() {
global $post;
$subtitle = get_post_meta($post->ID, 'link', true);
if(!empty($subtitle)){
echo __("\n<br />\n<br />Enter this competition for free:", '');
echo '<h3>'.$subtitle.'</h3>';
}
}
尽管此显示应在前端显示,但该URL不是链接。
function subtitle_link() {
global $post;
// Make sure this works!
$subtitle = get_post_meta($post->ID, 'link', true);
// If the above works, remove this!
$subtitle = 'http://www.google.com';
if( $subtitle ) {
echo __("\n<br />\n<br />Enter this competition for free:", '');
echo "<h3><a href='" . $subtitle . "'>My url</a></h3>";
}
}
add_action('woocommerce_single_product_summary', 'subtitle_link', 15);