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.
This website uses cookies

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services.

Cookies are small text files that can be used by websites to make a user's experience more efficient.

The law states that we can store cookies on your device if they are strictly necessary for the operation of this site. For all other types of cookies we need your permission. This means that cookies which are categorized as necessary, are processed based on GDPR Art. 6 (1) (f). All other cookies, meaning those from the categories preferences and marketing, are processed based on GDPR Art. 6 (1) (a) GDPR.

This site uses different types of cookies. Some cookies are placed by third party services that appear on our pages.

You can at any time change or withdraw your consent from the Cookie Declaration on our website.

Learn more about who we are, how you can contact us and how we process personal data in our Privacy Policy.

Please state your consent ID and date when you contact us regarding your consent.