0
add_action( 'init', 'wc_readd_add_to_cart_buttons' );
function wc_readd_add_to_cart_buttons() {
  //add to cart button loop
  add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}

I am adding back a button in WooCommerceand need to have a <br> before the button. How do I insert a <b> inside the above action?

closed as off-topic by Michael, Nathan Johnson, Mark Kaplun, Jacob Peattie, Jack Johansson Mar 27 '18 at 15:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2

Not sure why you are using init and then adding the function to the WC action. The following should work:

add_action( 'woocommerce_after_shop_loop_item', 'wc_readd_add_to_cart_buttons', 10 );
if (!function_exists('wc_readd_add_to_cart_buttons')){
   function wc_readd_add_to_cart_buttons() {
    //add to cart button loop
    echo "<br />";
    woocommerce_template_loop_add_to_cart();
  }
}
2

You can use 'echo' (or 'print') to enclose HTML, but sometimes that gets a bit messy with complex HTML, not to mention having to escape quote/double-quote character.

So try something like this:

function myfunction() {
  // after this next, plain HTML
  ?>
  <div class='myclass'><h1 align="center">This is a heading</h1></div>
  <!-- more HTML code here -->
  <?php   // back to PHP
  // .. some more PHP stuff
return;
}

That allows you to put in some complex HTML (or a bunch of it) without having to use echo/print.

Not the answer you're looking for? Browse other questions tagged or ask your own question.