有多種方法可以做到這一點,在這裏你會得到他們的2 ...
1)最簡單的方法(假設是簡單的產品)是使用掛鉤自定義功能在woocommerce_price_html
過濾器機以顯示在你的產品的價格這個圖標:
add_filter('woocommerce_price_html', 'prepend_append_icon_to_price', 10, 2);
function prepend_append_icon_to_price($price, $instance) {
// For home page only and simple products
if(is_front_page()){
// Your icon
$icon = ' <i class="fa fa-circle fa-rotate-270" aria-hidden="true"></i> ';
// Prepending and appending your icon around the price.
$price = $icon . $price . $icon;
}
return $price;
}
的代碼放在你的活躍兒童主題(或主題)的function.php文件或也以任何插件文件。
此代碼已經過測試並可正常工作。
2)您也可以使用wp_footer
行動鉤勾住了自定義函數使用jQuery你的圖標註入角落找尋價格:
add_action('wp_footer', 'prepend_append_icon_to_price');
function prepend_append_icon_to_price() {
if(is_front_page()){
?>
<script>
(function($){
var myIcon = ' <i class="fa fa-circle fa-rotate-270" aria-hidden="true"></i> ';
$('.home .woocommerce .price').prepend(myIcon).append(myIcon);
})(jQuery);
</script>
<?php
}
}
的代碼都在function.php文件你活躍的孩子主題(或主題),或任何插件文件。
此代碼已經過測試並可正常工作。
感謝LoicTheAztec。你的第一個建議工作得很好。作爲一個側面的問題,可以將相關的WooCommerce php文件(來自WooCommerce插件)放入主題文件夾中,然後相應地編輯該文件,是另一種選擇,還是被認爲不是很好的做法? – Craig
非常好。幾乎和我在想什麼一樣,所以謝謝你提供了更多的見解。投票正在進行中! :-) – Craig