This topic has 3 replies, 2 voices, and was last updated 3 years, 2 months ago ago by Fiz
Hi, i want to add a member_price custom text on shop loop, below the product price.
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_sale_percentage_loop', 25 );
function bbloomer_show_sale_percentage_loop() {
global $product;
if ( $product->is_type( 'simple' ) ) {
$member_price = $product->get_regular_price() - ($product->get_regular_price() * 0.2);
} elseif ( $product->is_type( 'variable' ) ) {
$member_price = 0;
foreach ( $product->get_children() as $child_id ) {
$variation = wc_get_product( $child_id );
$price = $variation->get_regular_price();
$member_price = $price - ($price * 0.2);
}
}
echo '<div class="member-price">' . __('Member Price') . ': ' . wc_price( $member_price ) . '</div>';
}
It display fine on 2021 theme, but not displaying on xstore. do i need to make change on the theme files directly? if so which file? and it would be great if I dont need to edit the theme files directly because it will be wiped out when updated.
Hello,
Try to use woocommerce_after_shop_loop_item_title
hook instead of the woocommerce_after_shop_loop_item
Regards
thanks. worked perfectly.
Tagged: best selling, custom field, optimized, plugin, shop loop, themes, woocommerce
The issue related to '‘Woocommerce Custom Field on shop loop’' has been successfully resolved, and the topic is now closed for further responses