# Code snippets

For simple features that require PHP, we use free Code Snippets plugin but you can replace it with any similar plugin or place the code in the child theme.

You can download them via your account your copy them directly here:

{% embed url="<https://bricksboilerplate.com/snippets/>" %}

| Snippet name                                            | Purpose                                                                                                                                     |
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| **Get product gallery image IDs**                       | Function to get the product gallery image IDs for the given product - will be depreceated when Bricks 1.11 is released                      |
| **Bricks whitelisting**                                 | Whitelist all echo functions used in Bricks                                                                                                 |
| **Get first image of product gallery**                  | Return the first image of product gallery. This will allows you to show second image alongside featured image of the product in query loop. |
| **Display last order in customer dashboard**            | Create a shortcode that contains information on the last order                                                                              |
| **Get customer total order count**                      | Return the total number of orders of customer                                                                                               |
| **Get customer total order sum**                        | Return the total sum of Completed orders of customer                                                                                        |
| **Get order status in order table**                     | Show order status in order table                                                                                                            |
| **Add Wishlist endpoint to My account page**            | Create a custom endpoint for My account page - Wishlist                                                                                     |
| **Get discounted amount**                               | Calculates how much the discount. Regular price minus sale price.                                                                           |
| **Autocart update on quantity change**                  | Update cart page on quality change                                                                                                          |
| **Show product images in My Account - Order details**   | Display images in Order details                                                                                                             |
| **Display active shipping method in cart totals**       | Display selected shipping method in Cart totals element                                                                                     |
| **Custom product reviews tags**                         | Create dynamic tags related to product reviews.                                                                                             |
| **Get all product gallery images**                      | Returns all product gallery images + featured image so you can use it with Image gallery element                                            |
| **Allow extra custom HTML tags bricks 1.10.3**          | Whitelist custom HTML tags                                                                                                                  |
| **Get remaining amount for free shipping**              | Get remaining amount for free shipping based on Woocommerce settings                                                                        |
| **Get cart subtotal**                                   | Return cart subtotal                                                                                                                        |
| **Display active shipping method in checkout totals**   | Display selected shipping methods in checkout total element                                                                                 |
| **Redirect to custom Thank you page**                   | Redirecting customers to custom thank you page                                                                                              |
| **Return order status**                                 | Return order status                                                                                                                         |
| **Set number of days to show "New" badge for products** | Set number of days when the product is labelled as "New"                                                                                    |
| **Check if product type is Simple**                     |                                                                                                                                             |
| **Check if product category has sub categories**        |                                                                                                                                             |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.brickstheme.com/basics/code-snippets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
