Parse error: syntax error, unexpected ‘endforeach’ (T_ENDFOREACH) in [closed]

When you use endforeach;, you have to use : instead off { when starting the foreach. <ul class=”project-extension-side-link”> <?php foreach($projectextensions as $projectextension) : // <— ?> <li <?php echo ($section==’project-extension’ ? ‘class=”active”‘: ”); ?>><span>Project 1</span></li> <li><a href=””><?php echo $projectextension->post_title; ?></a></li> <li><a href=””>Project 3</a></li> <li><a href=””>Project 4</a></li> <li><a href=””>Project 5</a></li> <li><a href=””>Project 6</a></li> <?php endforeach; ?> … Read more

Add product to cart from functions.php

I’ve figured it out function my_custom_function() { global $woocommerce; if ( $_SERVER[‘REQUEST_URI’] == ‘/checkout/?a=b’ ) { $woocommerce->cart->add_to_cart( 90759, 1 ); // exit; } } add_action( ‘init’, ‘my_custom_function’, 7 );

how to handle multiple forloop?

You can do something like this public function getStuffDone() { $order_ids = array( 358,368 ); $items = array(); // contains the names foreach ( $order_ids as $order_id ) { $order = wc_get_order( $order_id ); foreach ( $order->get_items() as $item_values ) { $items[ $order_id ][] = $item_values->get_name(); // add the name to the array } } … Read more

I want to add the alt attribute to all the photos!

If your current code manages all blocks with images replacing usage wp_get_attachment_image_src with output of hardcoded img tag, with echo wp_get_attachment_image() which will return img tag as string with default alt of image or empty if non set will work. Below is your code updated with idea described. <?php class home_main_post_below_list extends AQ_Block { //set … Read more

500 error after upgrading from 5.0 to 5.4 and adding empty functions.php

I’ve managed to print the error message by adding the following to the functions.php: function exception_handler($exception) { echo “Uncaught exception: ” , $exception->getMessage(), “\n”; } set_exception_handler(‘exception_handler’); For some reason logs did not include the error details before. The error is call to undefined function is_blog_installed() which I have no idea why’s that. 😀

Get term count on a category page

Rather than adding shortcode you have to add the hook which is on the product category page: // Use this hook for working directly on category page // add_action( ‘woocommerce_archive_description’, ‘show_category_product_counts’, 10 ); // Use this shortcode hook if you want to put on anywhere in the category page if you are using Elementor/WPBakery add_shortcode( … Read more