Woocommerce Custom Field on shop loop - by Fiz

This topic has 3 replies, 2 voices, and was last updated 3 years, 2 months ago ago by Fiz

  • Avatar: Fiz
    Fiz
    Participant
    October 12, 2021 at 11:50

    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.

    2 Answers
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    October 12, 2021 at 22:20

    Hello,

    Try to use woocommerce_after_shop_loop_item_title hook instead of the woocommerce_after_shop_loop_item

    Regards

    Avatar: Fiz
    Fiz
    Participant
    October 13, 2021 at 02:29

    thanks. worked perfectly.

  • Viewing 3 results - 1 through 3 (of 3 total)

The issue related to '‘Woocommerce Custom Field on shop loop’' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.