久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

基于產品類型的 WooCommerce“添加到購物車"按

Custom Button next to “ADD TO CART” button of WooCommerce based on Product Type(基于產品類型的 WooCommerce“添加到購物車按鈕旁邊的自定義按鈕)
本文介紹了基于產品類型的 WooCommerce“添加到購物車"按鈕旁邊的自定義按鈕的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想根據產品類型在 WooCommerce 的添加到購物車"按鈕旁邊添加一個自定義按鈕查看演示",無論是在主商店頁面還是單個產品頁面上.

I want add a custom Button "View Demo" next to "Add to Cart" button of WooCommerce based on Product Type, both on main shop page and single product page.

我已經完成了以下步驟:

I've done this steps:

添加代碼到主題文件header.php:

<script>var url_demo = "<?php echo the_field('url_demo'); ?>"</script>

使用TC Custom JavaScript"插件添加 jQuery 腳本:

Add jQuery script using "TC Custom JavaScript" plugin:

jQuery(function($) {
 $('.add_to_cart_button, .single_add_to_cart_button').after(' <a class="button demo_button" style="padding-right: 0.75em;padding-left: 0.75em;margin-left: 8px; background-color: #0ebc30;" href="'+url_demo+'" target="_blank">View Demo</a>');
});

它的工作,主商店頁面和單個產品頁面上顯示的自定義按鈕查看演示".

It's work, the Custom button "View Demo" shown on main shop page and single product page.

但我現在遇到了一些問題,查看演示"按鈕鏈接僅在單個產品頁面上正確,而在商店主頁上的查看演示"按鈕鏈接到相同的網址.我上面的代碼有錯嗎?

But I've some problem now, the "View Demo" button link only correct on Single Product page, while on shop main page the "View Demo" button, link to the same url. Is my code above wrong?

我的問題是,如何添加僅針對特定產品類型顯示的查看演示"按鈕(在主商店頁面和單個產品頁面上),例如僅在類別主題上顯示?最后,有沒有其他方法可以像上面的方法一樣在不編輯 header.php 文件的情況下添加演示鏈接?我只是期待 header.php 文件在主題更新時重置.

My questions are, how to add "View Demo" button (both on main shop page and single product page) that only show for spesific product type, for example only show on category Theme? Last, is there any other way to add demo link without editing the header.php file like above method? I just anticipating the header.php file reset if the theme updated.

推薦答案

我正在使用另一種方法:WooCommerce hooks.

I am using another way to do it: WooCommerce hooks.

您不再需要 jQuery 腳本以及位于 header.php 文件中的 javascript,因此您可以刪除它們.

You don't need anymore the jQuery script and also the javascript located in your header.php file, so you can erase them.

使用 get_field() 而不是 the_field(感謝 Deeptichipdey) 只獲取在 echoed 字符串中連接的值.

Using get_field() instead of the_field (thanks to Deepti chipdey) to get only the value concatenated in the echoed string.

將此代碼片段粘貼到位于活動子主題或主題文件夾中的 function.php 文件中:

Paste this code snippet in your function.php file located in your active child theme or theme folder:

function wc_shop_demo_button() {
    echo '<a class="button demo_button" style="padding-right: 0.75em;padding-left: 0.75em;margin-left: 8px; background-color: #0ebc30;" href="'.get_field( "url_demo" ).'" target="_blank">View Demo</a>';
}
add_action( 'woocommerce_after_shop_loop_item', 'wc_shop_demo_button', 20 );
add_action( 'woocommerce_after_add_to_cart_button', 'wc_shop_demo_button', 20 );

我已經瞄準了用于在商店頁面和單個產品頁面上顯示添加到購物車按鈕的鉤子,在它之后顯示您的查看演示按鈕,購買降低優先.

I have target the hooks used to display Add to cart button on shop page and in single product pages, to display your View demo button after it, buy lowering the priority.

這篇關于基于產品類型的 WooCommerce“添加到購物車"按鈕旁邊的自定義按鈕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 成人精品一区二区三区中文字幕 | 久久久www | 在线一区视频 | 91精品国产乱码久久久久久久久 | 国产激情精品一区二区三区 | 欧美日韩免费视频 | 夜夜艹天天干 | 影音先锋中文字幕在线观看 | 亚洲色欲色欲www | 四虎在线观看 | 午夜a v电影| 亚洲日本欧美日韩高观看 | 视频国产一区 | 久草在线在线精品观看 | 九一视频在线观看 | av免费网站在线观看 | av黄色在线 | 中文字幕在线播放第一页 | 日本不卡一区 | 日本黄视频在线观看 | 理论片午午伦夜理片影院 | 麻豆国产一区二区三区四区 | 日本成人在线免费视频 | 一区二区三区四区免费在线观看 | 国产免费观看一级国产 | a级在线免费观看 | 日本精品视频在线观看 | 在线一区视频 | 久久99深爱久久99精品 | 在线欧美亚洲 | 日韩视频a| 国内精品久久久久久 | 成人av网页 | 久草色视频 | 亚洲成人精品一区二区 | 国产专区在线 | 日韩中文字幕在线视频 | 中文字幕一区二区三区四区 | 日韩三级在线 | 久久精品亚洲国产 | 日韩国产一区二区三区 |