• Resolved catheg

    (@catheg)


    Hi there,

    I need to display the custom attributes of my products, not in a table like in the additional information but in a list separated with coma.
    I try to code that in the functions.php of my child theme.

    Trying to get the value of an attribute, I have the following error :
    Uncaught Error: Call to a member function get_attribute() on bool

    Here is the beginning of my code :
    global $product;
    $product = wc_get_product();
    echo $product->get_attribute( ‘couleur’ );

    Thanks for your help.

    Catherine.

Viewing 6 replies - 1 through 6 (of 6 total)
  • con

    (@conschneider)

    Engineer

    Hi there,

    I reckon you need to pass a parameter for $product = wc_get_product(); >> $product = wc_get_product(some_id); – right now $product is probable null and that causes the on bool error.

    Kind regards,

    Thread Starter catheg

    (@catheg)

    Thanks @conschneider .

    But I need to get the current product. So I don’t have any id ???

    Hi there,

    > need to get the current product. So I don’t have any id

    It depends on how you arrive at

    need to display the custom attributes of my products

    Thread Starter catheg

    (@catheg)

    Hi @kosiew ,

    Sorry for my dummy question, I’m just starting the customization of woocommerce using the hooks. The code below works fine, but I want to display this information below the title of the product in the single product page.
    Is there a hook to do this.
    Where can I find the complete list of hooks.

    add_action( ‘woocommerce_before_add_to_cart_form’, ‘get_product_attributes’, 60);
    function get_product_attributes()
    {
    global $product;

    // get the product attributes to display
    $product_couleur = $product->get_attribute( ‘couleur’ );

    // display the product attributes
    echo ‘<h5>’;
    echo $product_couleur;
    echo ‘</h5>’;
    )

    Thx.

    Hi there,

    > Sorry for my dummy question

    Questions are always welcome 😄

    > Where can I find the complete list of hooks.

    You can read more about the list of hooks here:

    http://docs.woocommerce.com/wc-apidocs/hook-docs.html

    I hope this points you in the right direction.

    It looks like you may have found a solution to this. I am going to mark this as Resolved at this time. If you have another issue please feel free to open a new post. 🙂

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Uncaught Error: Call to a member function get_attribute() on bool’ is closed to new replies.