• Resolved ryan0432

    (@ryan0432)


    Hello guys,

    I am not building a website for the company that has more than 5000 products.
    I wonder if there is anyway to use WooCommerce product attribute value for table ID so I don’t have to copy and paste for each entry.
    I’d like to know how I can do that. Thanks in advance.

Viewing 15 replies - 1 through 15 (of 25 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    I don’t see a reason why your table IDs could not be the WooCommerce product number, but you’d have to manually assign/adjust the table ID. You can easily edit it on the table’s “Edit” screen.

    Regards,
    Tobias

    Thread Starter ryan0432

    (@ryan0432)

    Hi @tobiasbg
    Thanks for your reply. But instead of entering the WooCommerce product number manually, is there any way I can use a short code in the template that I don’t enter the data one by one?
    Thanks

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    I don’t see how that could work, sorry. You’d need to link the product to the table somehow, so there has to be some sort of assignment…

    Regards,
    Tobias

    Thread Starter ryan0432

    (@ryan0432)

    Hi @tobiasbg
    I use WPBakery to assign the TablePress shortcode to create new a element

    View post on imgur.com

    I wonder if it can use a woocommerce short code “inside of TablePress short code”
    EX:[table id=”[product_attribute]” /]
    Something like this, thanks

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ah, I see. Yes, this is possible, if you define your own Shortcode. For example, add this to the end of your theme’s “functions.php” file:

    add_shortcode( 'table-wc', 'ryan0432_tablepress_woocommerce_shortcode' );
    function ryan0432_tablepress_woocommerce_shortcode( $atts ) {
      $atts['id'] = do_shortcode( '[product_attribute]' );
      return tablepress_get_table( $atts );
    }

    Then, you would use [table-wc /] as the Shortcode for the table on the pages. Inside that PHP code, you’d also need to adjust [product_attribute] as necessary.

    Regards,
    Tobias

    Thread Starter ryan0432

    (@ryan0432)

    Hi @tobiasbg,

    Thanks a lot for the code help.
    I will give it a try asap and let you know if it works. ??

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem! I hope it helps!

    Best wishes,
    Tobias

    Thread Starter ryan0432

    (@ryan0432)

    Hi @tobiasbg,

    I made a bit change on the code you provided.

    add_shortcode( 'table-wc', 'champion_tablepress_woocommerce_shortcode' );
    
    function champion_tablepress_woocommerce_shortcode( $partNum ) {
        global $product;
        $partNum = $product->get_sku();
        return tablepress_get_table( $partNum );
    }

    But it doesn’t seem to do anything. Can you please help me out on this?
    Thanks ??

    • This reply was modified 5 years ago by ryan0432.
    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    please try something like

    add_shortcode( 'table-wc', 'champion_tablepress_woocommerce_shortcode' );
    function champion_tablepress_woocommerce_shortcode( $atts ) {
      global $product;
      $partNumber = $product->get_sku();
      $atts['id'] = (string) $partNumber;
      return tablepress_get_table( $atts );
    }

    You would then have to use the Shortcode [table-wc /] on the page where you want to show the table. What are you seeing when you do that? For debugging, to see if you get the proper $partNumber, you could also use

    return $partNumber;
    

    Regards,
    Tobias

    Thread Starter ryan0432

    (@ryan0432)

    Here is the code
    https://imgur.com/ueFOyfM

    This is the markdown
    https://imgur.com/x7hJsfm

    This is the result
    https://imgur.com/DAA36lW

    It seems not working. It doesn’t register the shortcode. Very strange.
    I have pasted the code in every “functions.php” I could find in my project file.
    Do I have to create a separate “functions.php” somewhere else in the theme folder?

    • This reply was modified 5 years ago by ryan0432.
    Thread Starter ryan0432

    (@ryan0432)

    Hi @tobiasbg

    I am now using a plug-in called “Code Snippets” That seems to resolve the issue of “functions.php” not picking up the code.

    It resolves another problem that I needed to change the default options of TablePress, which the filter hook you provided on that issue works perfectly.

    But in this topic where it needs to take in Woocommerce SKU/Attribute value doesn’t seem to be working.

    Interestingly, if I use the Code Snippets plugin and WPBakery together, it will give me
    [table “” not found /] instead of not not registerning the shortcode

    Like this: https://imgur.com/J0Io1V7

    I guess it is probably the

      global $product;
      $partNumber = $product->get_sku();

    went wrong. Maybe the declaration didn’t pick up $product->get_sku() at all.

    Thanks for your patience, a lot,I know this has been dragged quite long.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    that new table not found message is a progress. This means that the Shortcode is working, but indeed, the retrieval of the part number is not yet working.
    You might need a different code from WooCommerce for that. It could be that $product is not a global variable, and that you might have to call a different PHP function from WooCommerce first (to get the product “loaded”).

    Regards,
    Tobias

    Thread Starter ryan0432

    (@ryan0432)

    Hi @tobiasbg

    Just a quick question. Normally how do I make a function that can printf the return value of $product->get_sku(); in Chrome Console?
    I have searched online and couldn’t find what the return value of that function is.
    According to the woocommerce manual, declaring global $product; should be getting the global variable of the individual product.
    If I can get it printed in console, we shall be able to see if we are getting the correct reference and return value.
    Thanks

    • This reply was modified 5 years ago by ryan0432.
    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    you won’t really be getting that in the Chrome console, as it’s PHP and not JavaScript.
    You could try a Shortcode wrapper:

    add_shortcode( 'sku_debug', 'ryan_sku_debug' );
    function ryan_sku_debug() {
      global $product;
      $partNumber = $product->get_sku();
      return var_export( $partNumber, true );
    }

    and then place the Shortcode [sku_debug] somewhere on the page.
    You could also do that with $product to inspect that variable;

    Regards,
    Tobias

    Thread Starter ryan0432

    (@ryan0432)

    Hey @tobiasbg

    Thanks for the snippet, I will try that on Monday.
    Hopefully it works ??
    I will let you know the result and see what else we can do to properly get the global reference from woocommerce.
    Have a lovely Friday.

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘Is it possible using WooCommerce product attribute value for Table ID?’ is closed to new replies.