Support » Plugin: Brands for WooCommerce » Get brand ID from current product

  • Resolved claudio323

    (@claudio323)


    Good day, I am trying to get the brand ID in the product page. How can I achieve this?

    I tried

    $brand_id = get_the_terms($post->ID, ‘product_brand’); // also ‘brand’
    $brand_id = wp_get_post_terms( $post->ID, ‘product_brand’, array( ‘fields’ => ‘names’ ) );

    There isn’t any brand in the variables $post or $product, therefore I get an “invalid_taxonomy” error message.

    Any idea about how to get the brand ID in php?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author RazyRx

    (@razyrx)

    Hello,

    For this plugin taxonomy name is berocket_brand, that is why product_brand is invalid taxonomy.

    Regards,
    Oleg

    Thread Starter claudio323

    (@claudio323)

    Great! I still can work with slugs instead of ID.

    Thanks!!

    Hi i have try get_the_terms($post->ID, ‘product_brand’);
    and get_the_terms($post->ID, ‘berocket_brand’); but i can’t get the brand, please help me

    add_action(‘woocommerce_thankyou’, ‘request_api_accesstrade’);
    function request_api_accesstrade($order_id)
    {
    $order = wc_get_order( $order_id );
    $line_items = $order->get_items();
    $items=array();
    $date = date(‘Y-m-d H:i:s’);
    foreach ( $line_items as $item ) {
    $product = $order->get_product_from_item( $item );
    $sku = $product->get_sku();
    $qty = $item[‘qty’];
    $total = $order->get_line_total( $item, true, true );
    $subtotal = $order->get_line_subtotal( $item, true, true );
    array_push($items, $item);
    }
    $arr_item = array();
    $count = sizeof($items);
    $tracking_id = $_COOKIE[‘_aff_sid’];
    for ($i=0; $i < $count; $i++) {
    //var_dump(get_the_terms( $items[$i][‘product_id’], ‘product_cat’ ));exit;
    array_push($arr_item, array(
    “id” => strval($items[$i][‘product_id’]),
    “sku” => strval($items[$i][‘product_id’]),
    “name” => strval($items[$i][‘name’]),
    “price” => $items[$i][‘subtotal’]/$items[$i][‘quantity’],
    “quantity” => $items[$i][‘quantity’],
    “category” => get_the_terms( $items[$i][‘product_id’], ‘product_cat’ )[0]->name,
    “category_id” => strval(get_the_terms( $items[$i][‘product_id’], ‘product_cat’ )[0]->term_id)
    ));
    }

    Plugin Author Dima Holovnia

    (@dholovnia)

    Hi,

    get_the_terms($post_id, 'berocket_brand'); cannot not work. We are using it in the plugin itself. Please test it without other code to be sure that it is working for you.

    Regards,
    Dima

    giovanicoutinho

    (@giovanicoutinho)

    Hi,

    I need suport to filter automatically in the simple page of product, the same products with the same SKU of this sku current.
    Can you help-me?
    I’m beginner

    Plugin Author Dima Holovnia

    (@dholovnia)

    Hi @giovanicoutinho,

    Please create own support topic.

    Regards,
    Dima

    Hi Dima,

    How link to create the suport in a new topic?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.