Forum has been created to help all our customers in properly working our theme. We offer complete help with configuration theme and make default look, just like on our Be|theme demo. We don`t offer theme customization.


Before creating a new discussion, please:
1. Check on forum if discussion hasn`t been created before. Use the forum Search on the right.
2. Read carefully the documentation included to package.
3. If you didn`t find what you need and would like to post a new question click the "Start a New Discussion" button on the right.
4. You can post on forum only after registration (you need purchase code to register) .


NOTE!!! If you are starting a new topic and have got problems with your site and you want us to check what`s wrong please always give url to your site because without that we can`t check what`s wrong. Each case may be different because of your installed plugins, servers or other things.


IMPORTANT!!! Along with your inquiry, please attach the address of the page which concerns the question. This will cause the time to answer on your question will be much shorter. If you do not want to publish your address publicly in the forum, please send a private message. Thanks!

Request: Add data-product_sku to the "Add to Cart" links or allow customizing data attributes.

I really need to add product SKU to the Add to Cart links to use it in my JS code. That seemed to be easy because WooCommerce provides some helpful hooks, for example woocommerce_loop_add_to_cart_args or woocommerce_loop_add_to_cart_link. None of these works in BeTheme because the add to cart links are hardcoded in the the content-product.php file.  The only way to add custom attributes to the add to cart link without modifying  BeTheme is to apply the following  hack. Could you see if you can rework the content-product.php and utilize the woocommerce_loop_add_to_cart_args when generating add to cart links?

 
function custom_add_to_cart_url( $url ) {
global $product;
return $url . '" ' . 'data-product_sku="' . $product->get_sku();
}
add_filter('add_to_cart_url','custom_add_to_cart_url' );

Comments

  • Please sign in to see answear!
  • Thanks for the quick reply. It looks like there is a misunderstanding. I am trying to avoid any file customization in BeTheme or WooCommerce. The current implementation of BeTheme for WooCommerce seems to be limited in a way that it does not allow to use some of the WooCommerce hooks such as  woocommerce_loop_add_to_cart_args or woocommerce_loop_add_to_cart_link. Please notice that WooCommerce adds the data-product_sku attribute to the "Add to Cart" link by default. (see the woocommerce_template_loop_add_to_cart function in the wc-template-functions.php file in WooCommerce; also you can check html for the Add to Cart button in the official WooCommerce theme). If the BeTheme WooCommerce didn't have that limitation, I wouldn't need to make any changes at all. So my hope is that the issue is addressed for all BeTheme customers in one of the future updates. As for now, I have to use the workaround with the add_to_cart_url filter. 


  • Please sign in to see answear!
Sign In or Register to comment.