WooCommerce在特定类别的单产品页面上的自定义按钮

发布于 2025-02-12 05:09:18 字数 912 浏览 1 评论 0原文

您好,下面的代码正常工作,但这并不是“添加到购物车”按钮的内联。我希望此自定义按钮内联添加到购物车中。

add_action( 'woocommerce_single_product_summary', 'custom_button_by_categories', 36 ,0 );
function custom_button_by_categories(){
    
    global $product;

    // Define your categories in this array (can be Ids, slugs or names)
    $product_cats = array('mobile-touch', 'music', 'furnitures');

    if( has_term( $product_cats, 'product_cat', $product->get_id() ) ){
         $demo_url = get_post_meta( $product->get_id(), 'demo_url', true );
         echo '<a class="fancybox iframe" data-width="1280" data-height="820" a href="https://lab.dmarket.pk/" target="_blank" rel="noopener"><button style="background: #007bc4; color: #ffffff; border-radius: 5px;margin-top: -120px !important;margin-left: 220px !important; padding-left: 19px; padding-right: 19px;"> Fix My Device</button></a>';
    }
}

Hello This Below Code is working fine but this is not inline to "Add to Cart" button. I Want This Custom Button To Inline Add To Cart.

add_action( 'woocommerce_single_product_summary', 'custom_button_by_categories', 36 ,0 );
function custom_button_by_categories(){
    
    global $product;

    // Define your categories in this array (can be Ids, slugs or names)
    $product_cats = array('mobile-touch', 'music', 'furnitures');

    if( has_term( $product_cats, 'product_cat', $product->get_id() ) ){
         $demo_url = get_post_meta( $product->get_id(), 'demo_url', true );
         echo '<a class="fancybox iframe" data-width="1280" data-height="820" a href="https://lab.dmarket.pk/" target="_blank" rel="noopener"><button style="background: #007bc4; color: #ffffff; border-radius: 5px;margin-top: -120px !important;margin-left: 220px !important; padding-left: 19px; padding-right: 19px;"> Fix My Device</button></a>';
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无名指的心愿 2025-02-19 05:09:18

woocommerce_single_product_summarywoocommerce_after_add_to_cart_cart_button应该做工作

Replacing woocommerce_single_product_summary with woocommerce_after_add_to_cart_button should do the job

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文