• Resolved muleque

    (@muleque)


    I want to show the product units and unit (e.g. 10 Kg) next to the price and I am wondering how I can acess these attributes within the funcitons.php of my child theme.
    I have the following function where Einheit_pa is a custom attribute. This I want to change to the product units and unit.

    add_filter( 'woocommerce_get_price_suffix', 'price_suffix', 99, 4 );
     
    function price_suffix( $html, $product, $price, $qty ){
       $ve = $product->get_attribute( 'Einheit_pa' );
       $html .= '  (' . $ve . ')';
    
       return $html;
    }
    • This topic was modified 4 years, 11 months ago by muleque.
    • This topic was modified 4 years, 11 months ago by muleque.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi

    I think the problem is the attribute name. Attributes are named in Woocommerce as follows:

    pa_Einheit

    Not

    Einheit_pa

    Try to change attribute name and check again.

    Good luck

    Thread Starter muleque

    (@muleque)

    @yazdaniwp thats the hint. my attribute was named Einheit_pa by myself. And I had to name it pa_einheit_pa to get the attribute correctly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP WC how to access product units and unit?’ is closed to new replies.