这对自定义链接重定向非常有用。
为要在其上使用自定义URL链接的某些woocommerce产品页面创建新的Wordpress自定义字段:
自定义字段名称:nothanks_link_redirect
自定义字段值:https://yourlinkforthispage.com
根据需要进行调整,并将其放入子主题的functions.php中:
/** WooCommerce custom field - 'No Thanks' Button **/
function nothanks_redirect_button() {
global $post;
$product_id = $post->ID;
$NoThanksLinkRedirectValue = get_post_meta($product_id,'nothanks_link_redirect',true);
if(!$NoThanksLinkRedirectValue) return;
echo '<a class="nothanks-button" style="margin-left: 20px" href="'.$NoThanksLinkRedirectValue.'" target="_self">No Thanks</a>';
}
add_action('woocommerce_after_add_to_cart_button','nothanks_redirect_button');
享受
请尝试在functions.php文件中的以下代码
function nothanks_link_redirect() {
echo '<a class="button nothanks_link_redirect" style="padding-right: 0.75em;padding-left: 0.75em; margin-left: 8px; " href="https://yourlinkforthispage.com" target="_blank">no thanks</a>';
}
add_action( 'woocommerce_after_shop_loop_item', 'nothanks_link_redirect', 20 );
add_action( 'woocommerce_after_add_to_cart_button', 'nothanks_link_redirect', 20 );