Hey I need to put "in stock" text after price at my shop page. Screen
I found this code
add_filter( 'woocommerce_get_price_html', 'prepend_append_icon_to_price', 10, 2 );
function prepend_append_icon_to_price( $price, $product ) {
if( has_term( 'fast-shipping', 'product_cat', $product->get_id() ) && ! is_product() ){
$price .= '<span style="float:right"><i class="fas fa-shipping-fast"></i></span> ';
}
return $price;
}
And I have this code
function envy_stock_catalog() {
global $product;
if ( $product->is_in_stock() ) {
echo '<div class="stock" >' . $product->get_stock_quantity() . __( ' in stock', 'envy' ) . '</div>';
} else {
echo '<div class="out-of-stock" >' . __( 'out of stock', 'envy' ) . '</div>';
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'envy_stock_catalog' );
Now i need to combine these codes, can you help me? Please:)
You can do such type of things to fulfill your requirement. You can place this code in your functions.php.
if(is_shop){
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 ); // remove previous price from shop
}
add_action('woocommerce_after_shop_loop_item_title','faastechies_solution');
function faastechies_solution(){
if(is_shop){
global $product;
// Add your template here according to your further requirement. Just add classes and ids and use this css in your custom css or custom css file.
?>
<span style="color:black; font-size: 16px font-weight: bold"> Price: <p
style="display: inline; font-size: 16px; color: red; font-weight: 600">
<? echo $product->get_regular_price();?>
</p> Status: <p style="display: inline; font-size: 16px; color: red; font-weight:
600">
<? echo $product->get_stock_status();;?>
</p></span>
<?
}}
Ok, thanks @fasstechies i edited the code and now it's working:) thx.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action('woocommerce_after_shop_loop_item_title','faastechies_solution');
function faastechies_solution(){
if (is_shop()){
global $product;
// Add your template here according to your further requirement. Just add classes and ids and use this css in your custom css or custom css file.
?>
<span style="color:black; font-size: 16px font-weight: bold"> Price: <p
style="display: inline; font-size: 16px; color: red; font-weight: 600">
<? echo $product->get_regular_price();?>
</p> Status: <p style="display: inline; font-size: 16px; color: red; font-weight:
600">
<? echo $product->get_stock_status();;?>
</p></span>
<?
}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.