Title: Syntax error activating snippet
Last modified: January 19, 2024

---

# Syntax error activating snippet

 *  [nanetteg](https://wordpress.org/support/users/nanetteg/)
 * (@nanetteg)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/syntax-error-activating-snippet/)
 * Hi,
 * I set up a snippet to make a change to a section in My Account. It had been working
   fine, but I noticed an error and realized that the snipped had been deactivated.
   I’m getting this error message:
 * We encountered an error activating your snippet, please check the syntax and 
   try again. Error message: `Call to a member function get_downloadable_products()
   on null`
 * I’m not a programmer, so I’m not sure what this means! The snippet is used to
   change the wording on the “Downloads” section of My Account. I changed the tab
   from “Downloads” to “Gift Certificates” and created this snippet to change the
   message that shows up when no gift certificates are available.
 * What does the error message mean, and, why did it work for weeks and then suddenly
   deactivate?
 *     ```wp-block-code
       <?php
   
       if ( ! defined( 'ABSPATH' ) ) {exit;}
   
       $downloads = WC()->customer->get_downloadable_products();$has_downloads = (bool) $downloads;
   
       do_action( 'woocommerce_before_account_downloads', $has_downloads ); ?>
   
       <?php do_action( 'woocommerce_before_available_downloads' ); ?>
   
       <?php do_action( 'woocommerce_available_downloads', $downloads ); ?>
   
       <?php do_action( 'woocommerce_after_available_downloads' ); ?>
   
       <?php
   
       $wp_button_class = wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '';
   
       wc_print_notice( esc_html__( 'No Gift Certificates available.', 'woocommerce' ) . ' <a class="button wc-forward' . esc_attr( $wp_button_class ) . '" href="' . esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ) . '">' . esc_html__( 'Browse products', 'woocommerce' ) . '</a>', 'notice' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
   
       ?>
   
       <?php do_action( 'woocommerce_after_account_downloads', $has_downloads );
       ```
   
 * Thanks so much!
 * Nan

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/syntax-error-activating-snippet/#post-17356129)
 * Hi Nan,
 * The error in this case is caused by trying to call get_downloadable_products 
   on the WC()->customer object without first checking if WC()->customer is set.
   You might also be executing the snippet too early.
 * You can wrap the code in a check like
 *     ```wp-block-code
       if ( ! is_null(WC()->customer) ) {
       // Your code here
       }
       ```
   
 * You can also try limiting execution of the snippet just for logged-in users –
   that could also prevent the error from being thrown.
 *  Thread Starter [nanetteg](https://wordpress.org/support/users/nanetteg/)
 * (@nanetteg)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/syntax-error-activating-snippet/#post-17356334)
 * Hi Mircea,
 * Thank you for this! I first tried limiting the execution and that didn’t work,
   so I added the check and didn’t get the error. However, it’s not executing the
   snippet like before. I’m still getting the original message of: “No downloads
   available yet.”
 * ![](https://wordpress.org/44516100-3ec3-4d6f-ab3f-9d4cede5329c)
 * I will keep digging….
 * Thanks!!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Syntax error activating snippet’ is closed to new replies.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [nanetteg](https://wordpress.org/support/users/nanetteg/)
 * Last activity: [2 years, 4 months ago](https://wordpress.org/support/topic/syntax-error-activating-snippet/#post-17356334)
 * Status: not resolved