Skip to content
Advertisement

Add custom “Add to cart” button based on ACF field to WooCommerce single product page

I want to add an additionall custom “Add to cart button” on the single product page conditionally using this code:

JavaScript

This variable is field from ACF $mamut = get_field('mamut');

However when I put this code into my functions.php file, the single product page crash

I am using theme Twenty nineteen and Elementor Pro.

I’ve tried to remove actions and then add different one but it doesn’t work. Also I tried to make shortcodes and enter them using Elementor , but then shortcodes displayed as text.

Advertisement

Answer

  • Your using $product->get_id(); while $product is not defined
  • You could use $product->get_stock_status(); instead of get_post_meta( get_the_ID(), '_stock_status', true );

So you get

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement