簡體   English   中英

自定義 Woocommerce 購物車小部件

[英]Customise Woocommerce cart widget

我正在嘗試自定義 woocommerce 購物車小部件並使其更“可視化”,如下例所示。 我已經研究過,似乎我可以通過鈎子woocommerce_mini_cart()用我自己的行為 覆蓋 woocommerce 購物車小部件

最終結果我想: 在此處輸入圖片說明

是否可以通過這種方法修改購物車小部件的核心功能以實現類似的功能,通過functions.php文件還是我還需要CSS?

if ( ! function_exists( ‘woocommerce_mini_cart’ ) ) {
function woocommerce_mini_cart( $args = array() ) {

$defaults = array( ‘list_class’ => ” );
$args = wp_parse_args( $args, $defaults );
woocommerce_get_template( ‘cart/mini-cart.php’, $args );

}
//*MODIFY HERE?*
}

或者,有人知道可以解決這個問題的 woocommerce 插件嗎?

盡管這個問題對於它的作者來說已經不是實際的了,
我想分享一些代碼來修改默認的 woocommerce_mini_cart() 輸出:
1) 最困難的一步 - 為 woocommerce_mini_cart() 函數禁用 ECHO
2) 根據需要更改輸出 HTML;
3) 回顯格式化的 HTML。

1)

function disable_echo_for_woocommerce_mini_cart() {
   $mini_cart_html = woocommerce_mini_cart(); 
   return $mini_cart_html;
}

2)

$mini_cart_html = disable_echo_for_woocommerce_mini_cart();
$mini_cart_html = str_replace('some_code', 'some_code_2', $mini_cart_html); // change output HTML.
$mini_cart_html = ob_get_clean();

3)

echo $mini_cart_html;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM