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

  • Hi,

    What you ask for, requires files customization what in reference to Item Support Policy is not allowed. So if you want to modify files and don't know how, you should contact your web developer. Item Policy says:
    Item support does not include services to modify or extend the item beyond the original features, style, and functionality described on the item page. For customization services that will help you tailor the item to your specific requirements, we recommend contacting the author to see if they privately offer paid customisation services or checking out the great service providers on Envato Studio

    thanks
  • 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. 


  • I provided this request to BeTheme developer team, and they said, that this will be included soon.

    Also, if you have more other ideas how BeTheme can be improved, please
    post it here: https://forum.muffingroup.com/betheme/discussion/113/your-suggestions-for-future-updates#latest
    We really appreciate this.
    Thanks.
Sign In or Register to comment.