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

更改 WooCommerce 迷你購物車小部件上的購物車和結

Change cart and checkout button links on WooCommerce mini cart widget(更改 WooCommerce 迷你購物車小部件上的購物車和結帳按鈕鏈接)
本文介紹了更改 WooCommerce 迷你購物車小部件上的購物車和結帳按鈕鏈接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在 Woocommerce 上,我們如何更改將鼠標懸停在主頁上的購物車圖標上時顯示的下拉菜單上的查看購物車"和結帳"鏈接上的 URL?

我設置了購物車"和結帳"頁面,但它們沒有鏈接到這些頁面.

我可以通過網(wǎng)址直接查看這些頁面.

解決方案

似乎您的主題在某處存在問題(或在插件中),因為迷你購物車按鈕鏈接始終指向正確的購物車和結帳頁面.

迷你車按鈕在 woocommerce_widget_shopping_cart_buttons 動作掛鉤(在cart/mini-cart.php WooCommerce 模板中)中掛鉤.您會在此處找到詳細信息/wc-template-hooks.php 核心文件.它調用2個顯示按鈕的函數(shù).

<塊引用>

首先,您應該嘗試刷新 WordPress 永久鏈接,繼續(xù) WP 設置 > 永久鏈接:
在頁面末尾點擊保存".清空您的購物車,然后再試一次,看看它是否有改變.

在下面的代碼中,我首先刪除了原始按鈕,然后將它們替換為自定義鏈接的相同按鈕.對于每個您可以更改鏈接以滿足您的需求(我在鏈接中添加了?id=1(最后)只是為了測試目的,以檢查更改):

add_action('woocommerce_widget_shopping_cart_buttons', function(){//刪除按鈕remove_action('woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10);remove_action('woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20);//添加自定義按鈕add_action('woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_button_view_cart', 10);add_action('woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_proceed_to_checkout', 20);}, 1 );//自定義購物車按鈕函數(shù) custom_widget_shopping_cart_button_view_cart() {$original_link = wc_get_cart_url();$custom_link = home_url( '/cart/?id=1' );//這里替換購物車鏈接echo '<a href="' .esc_url( $custom_link ) .'" class="button wc-forward">'.esc_html__( '查看購物車', 'woocommerce') .'</a>';}//自定義結賬按鈕函數(shù) custom_widget_shopping_cart_proceed_to_checkout() {$original_link = wc_get_checkout_url();$custom_link = home_url('/checkout/?id=1');//這里替換結帳鏈接echo '<a href="' .esc_url( $custom_link ) .'" class="button checkout wc-forward">'.esc_html__( 'Checkout', 'woocommerce') .'</a>';}

代碼位于活動子主題(或主題)的 function.php 文件或任何插件文件中.

所有代碼都在 Woocommerce 3+ 上進行了測試并且可以正常工作.

On Woocommerce, how can we change the URLs on "View cart" and "Checkout" links on the drop down menu that show up on hover over the shopping cart icon on the the home page?

I have the "cart" and "checkout" pages setup but they are not linked to these.

I can view these pages directly with urls. http://mysite/cart and http://mysite/checkout

解決方案

It seems that there is a problem somewhere with your theme (or in a plugin), as the minicart button links always point to the right cart and checkout pages.

The minicart buttons are hooked in woocommerce_widget_shopping_cart_buttons action hook (in the cart/mini-cart.php WooCommerce template). You will find the details HERE on includes/wc-template-hooks.php core file. It calls 2 functions that are displaying the buttons.

First you should try to refresh WordPress Permalinks, going on WP Settings > Permalinks:
Just at the end of the page click on "save". Empty your cart, and try it again to see if it changes something.

In the code below I remove first the original buttons and I replace them by the same ones where the links are customized. For each you can change the link to feet your needs (I have added in the links ?id=1 (at the end) just for testing purpose, to check changes):

add_action( 'woocommerce_widget_shopping_cart_buttons', function(){
    // Removing Buttons
    remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
    remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );

    // Adding customized Buttons
    add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_button_view_cart', 10 );
    add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_proceed_to_checkout', 20 );
}, 1 );

// Custom cart button
function custom_widget_shopping_cart_button_view_cart() {
    $original_link = wc_get_cart_url();
    $custom_link = home_url( '/cart/?id=1' ); // HERE replacing cart link
    echo '<a href="' . esc_url( $custom_link ) . '" class="button wc-forward">' . esc_html__( 'View cart', 'woocommerce' ) . '</a>';
}

// Custom Checkout button
function custom_widget_shopping_cart_proceed_to_checkout() {
    $original_link = wc_get_checkout_url();
    $custom_link = home_url( '/checkout/?id=1' ); // HERE replacing checkout link
    echo '<a href="' . esc_url( $custom_link ) . '" class="button checkout wc-forward">' . esc_html__( 'Checkout', 'woocommerce' ) . '</a>';
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

All code is tested on Woocommerce 3+ and works.

這篇關于更改 WooCommerce 迷你購物車小部件上的購物車和結帳按鈕鏈接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數(shù))
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)
主站蜘蛛池模板: 亚洲第一成人av | 一级aaaaaa毛片免费同男同女 | 色播99 | 91久久| 久久久久久综合 | 欧美一区二区三区国产精品 | 亚洲人成人一区二区在线观看 | 精品国产乱码一区二区三 | 性色在线 | 亚洲国产精品久久久久秋霞不卡 | 二区三区视频 | 精品一区二区三区日本 | 午夜在线视频 | 亚洲一区视频 | 99久久久无码国产精品 | 亚洲精品综合一区二区 | 成人超碰| 久久精品aaa| 欧美色性 | 欧美九九 | 欧美区日韩区 | 亚洲视频区 | 一区二区福利视频 | 99pao成人国产永久免费视频 | 久久另类视频 | 国产一伦一伦一伦 | 欧美成人在线免费 | 亚洲精品一区在线 | 国产精品性做久久久久久 | 一本一道久久a久久精品综合 | 日日夜夜精品视频 | 欧美激情国产日韩精品一区18 | 午夜精品久久久久久久99黑人 | 亚洲国产成人精品久久 | 亚洲欧美激情四射 | 精品二区视频 | 一区二区三区av | 欧美精品网站 | 丁香五月网久久综合 | 青青草网站在线观看 | 亚洲福利一区二区 |