我正在寻找一种在“添加到购物车”按钮旁边添加自定义按钮的方法,但是我可以在产品自定义元字段中输入按钮链接网址。
我为某些woocommerce产品页面创建了一个新的Wordpress自定义字段,我希望在其上具有附近的自定义网址按钮:
自定义字段名称:nothanks_link_redirect
自定义字段值:https://yourcustomlink.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');
/** 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');
请享用
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句