Skip Navigation

[Resolved] I cant save templates anymore

This thread is resolved. Here is a description of the problem and solution.

Problem:

The issue here is that the user was unable to save their content template.

Solution:

In this user's case it turned out to be their custom code. What I would do is that you remove the custom code from the site and save the template.

Also check that your custom code is correctly formatted and following the standard wordpress procedures.

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 32 replies, has 3 voices.

Last updated by jelle-jacobd 5 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#1186695

Hi,

I'm trying to save a template or a view, but I keep getting the error cant save template or error saving template.. what should I do?

#1186700

Diego Pereira
Supporter

Hello @jelle-jacobd, welcome to the Toolset support Forum!

Could you send us a screenshot of the error?

Please enable the PHP debug on your website. See instructions here: https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/#php-debugging - After that, please try to save the template again then send us the content of the error_log.txt file.

To ensure the quickest and most accurate support, please also provide your toolset debug information so that I can get a look at some of your configurations. We have an excellent article on how to located here: https://wpml.org/faq/provide-debug-information-faster-support/.
NOTE: Please be sure to check the box to indicate you can provide debug info and paste your debug info in the debug field provided, and NOT in the general response field.

All the best,
Diego

#1186720
Schermafdruk 2019-01-18 13.34.53.png

Thanks for getting back at me on such a short notice. Of course, I have uploaded the image and pasted the debug info in the debug box.

#1186727

Below the error log;

[18-Jan-2019 12:41:00 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_attribute() on null in /var/www/vhosts/light4u.io/products.light4u.io/wp-content/themes/Zephyr-child/functions.php:128
Stack trace:
#0 /var/www/vhosts/light4u.io/products.light4u.io/wp-includes/shortcodes.php(319): show_product_attribute_func(Array, '', 'show-product-at...')
#1 [internal function]: do_shortcode_tag(Array)
#2 /var/www/vhosts/light4u.io/products.light4u.io/wp-includes/shortcodes.php(197): preg_replace_callback('/\\[(\\[?)(show\\-...', 'do_shortcode_ta...', '<table>\n<tr>\n<t...')
#3 /var/www/vhosts/light4u.io/products.light4u.io/wp-includes/class-wp-hook.php(286): do_shortcode('<table>\n<tr>\n<t...')
#4 /var/www/vhosts/light4u.io/products.light4u.io/wp-includes/plugin.php(203): WP_Hook->apply_filters('<table>\n<tr>\n<t...', Array)
#5 /var/www/vhosts/light4u.io/products.light4u.io/wp-content/themes/Zephyr/framework/functions/meta-tags.php(69): apply_filters('us_page_block_t...', '<table>\n <tr>\n...')
#6 /var/www/vhosts/light4u.io/products.light4u.i in /var/www/vhosts/light4u.io/products.light4u.io/wp-content/themes/Zephyr-child/functions.php on line 128

#1186728

Does the theme force these errors? It was working before and I didn't update anything.

#1186745

Diego Pereira
Supporter

Hi there,

The issue seems related to the theme. Could you please test it with a default WP theme (like twenty-seventeen)?

Please also open a ticket with the theme support, so they can take a look at the issue.

Kind regards,
Diego

#1187674

Hi Diego,

I have contacted theme support and the found the issue is related to my funtions.php within the child theme. I'm not sure where to find to code that's going wrong or have been written wrong?

<?php
/* Custom functions code goes here. */

/* Sortering dropdown verwijderen/ */

remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering',30 );

/**
* Change number of products that are displayed per page (shop page)
*/
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );

function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 9999;
return $cols;
}

/* UPSOLUTION WOOCOMMERCE ATTRIBUTES GRID BUILDER ADD-ON */
add_shortcode('attr-woo-sale', 'us_get_woo_attr_sale');
function us_get_woo_attr_sale(){
global $product;
$att = $product->get_attribute( 'sale' );
return $att;
}

/* VERWIJDEREN TABBLADEN DESCRIPTION EN ADDITIONAL INFORMATION */
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );

// Change "You may also like" into "Family"

add_filter('gettext', 'translate_like');
add_filter('ngettext', 'translate_like');
function translate_like($translated) {
$translated = str_ireplace('You may also like…', 'FAMILY', $translated);
return $translated;
}

/* TOEGEVOEGD NAV TICKET TOOLSET IP WAARDES */

function has_woo_attr_term($term, $tax){
$res = '0';
if(has_term($term, $tax, null)){
$res = '1';
}
return $res;
}

/* PRODUCT SKU SHORTCODE */
function display_woo_sku() {

global $product;
return $product->get_sku();

}
add_shortcode( 'woo_sku', 'display_woo_sku' );

/* UPSELL TOEVOEGEN ALS FAMILY PRODUCTS */

function func_get_product_upsell_ids() {
global $post;

$product = new WC_Product($post->ID);
$upsells = $product->get_upsell_ids();
$upsells = isset($upsells[0]) ? $upsells : array(0);

return join(",",$upsells);

}
add_shortcode( 'get_upsell_ids', 'func_get_product_upsell_ids' );

/* CROSS SELL TOEVOEGEN ALS RELATED PRODUCTS */

function func_get_product_cross_sell_ids() {
global $post;

$product = new WC_Product($post->ID);
$cross_sells = $product->get_cross_sell_ids();
$cross_sells = isset($cross_sells[0]) ? $cross_sells : array(0);

return join(",",$cross_sells);

}
add_shortcode( 'get_cross_sell_ids', 'func_get_product_cross_sell_ids' );

/* DATASHEET FILTER */
add_filter('wpv_filter_query', function($query_args, $view_settings, $view_id){
if($view_id == 61161){
$query_args['post_type'] = 'product_variation';
}
return $query_args;

}, 10, 3);

/* PARENT SKU FOR PRODUCT TABLE LINK */

function wc_get_product_id_by_variation_sku($sku) {
$args = array(
'post_type' => 'product_variation',
'meta_query' => array(
array(
'key' => '_sku',
'value' => $sku,
)
)
);
// Get the posts for the sku
$posts = get_posts( $args);
if ($posts) {
return $posts[0]->post_parent;
} else {
return false;
}
}
add_shortcode( 'get_parent_sku', 'wc_get_product_id_by_variation_sku' );

/* DATASHEET PRODUCT ATTRIBUTES */

add_shortcode( 'show-product-attribute', 'show_product_attribute_func');
function show_product_attribute_func($atts){
$attribute = $atts['attribute'];

if ( !empty($attribute) ) {

global $product;

$value = $product->get_attribute( $attribute );

if (!empty($value)) {
return $value;
}
}
}
?>

#1188081

Diego Pereira
Supporter

Hi there,

According to your error log the issue seems related to the get_attribute() function:

[18-Jan-2019 12:41:00 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_attribute() on null in /var/www/vhosts/light4u.io/products.light4u.io/wp-content/themes/Zephyr-child/functions.php:128

I can see two calls of this function in your code:
- $value = $product->get_attribute( $attribute );
- $att = $product->get_attribute( 'sale' );

Kind regards,
Diego

#1188154

Hi Diego,

Thanks for getting back at me. I've found the code snippets below are forcing the error. One of them from one of your supporters, related to a solved ticket.

1: https://toolset.com/forums/topic/displaying-formatted-data-instead-of-raw-data/#post-1174069

Is there a way to rewrite them in order to get things working? These are not the same as the snippets you are referring to? When adding both or just one of them to my functions.php, Toolset wil throw an error and wont save the content templates or views.

/* DATASHEET PRODUCT ATTRIBUTES */
add_shortcode( 'show-product-attribute', 'show_product_attribute_func');
function show_product_attribute_func($atts){
$attribute = $atts['attribute'];

if ( !empty($attribute) ) {

global $product;

$value = $product->get_attribute( $attribute );

if (!empty($value)) {
return $value;
}
}
}

/* PRODUCT SKU SHORTCODE */
function display_woo_sku() {

global $product;
return $product->get_sku();

}
add_shortcode( 'woo_sku', 'display_woo_sku' );

#1188277

Diego Pereira
Supporter

Hi there,

It seems that this code snippet creates a shortcode to display the product attributes. It requests the global $product, which is set in the woocommerce product page. So it will now work inside of a view.

Please remove the shortcode from the view. Instead, you can use the [wpv-woo-list_attributes] to list the product attributes (see https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-woo-list_attributes).

Kind regards,
Diego

#1188286

HI Diego,

Thanks again. I was told the [wpv-woo-list_attributes] won't work in this particular case. I tried this first before contacting support before, that why this snippet was created. When placing the shortcode in the view, it doesn't display anything..

#1188329

Diego Pereira
Supporter

Hi,

I have updated the code with a IF to check if the global $product is set:

/* DATASHEET PRODUCT ATTRIBUTES */
add_shortcode( 'show-product-attribute', 'show_product_attribute_func');
function show_product_attribute_func($atts){
    $attribute = $atts['attribute'];
     
    if ( !empty($attribute) ) {
 
        global $product;
        
         if ( !empty( $product ) ) { 
            $value = $product->get_attribute( $attribute );  
            return $value;
        }
    }
}

Please let me know if it works for you. Please also remember to remove the other function with the same issue.

Kind regards,
Diego

#1188333

Thanks a lot, that worked:) What's the difference exactly and why isn't Toolset get stuck on this variant? I'm trying to understand so I can correct it myself in the future.

How should I change the code for the SKU, same way?

/* PRODUCT SKU SHORTCODE */
function display_woo_sku() {

global $product;
return $product->get_sku();

}
add_shortcode( 'woo_sku', 'display_woo_sku' );

#1188936

Hi Diego,

I also tried this variant, but it doesn't work and throws an error as well:

/**
* Echos the SKU for the product when used on a single product page
* Can optionally pass in the ID to echo the SKU for a product elsewhere
* Use [wc_sku] or [wc_sku id="ID"]
* Tutorial: hidden link
**/

function skyverge_get_product_sku( $atts ) {

global $product;

$atts = shortcode_atts( array(
'id' => '',
), $atts );

// If no id, we're probably on a product page already
if ( empty( $atts['id'] ) ) {

$sku = $product->get_sku();

} else {

//get which product from ID we should display a SKU for
$product = wc_get_product( $atts['id'] );
$sku = $product->get_sku();

}

ob_start();

//Only echo if there is a SKU
if ( !empty( $sku ) ) {
echo $sku;
}

return ob_get_clean();

}
add_shortcode( 'wc_sku', 'skyverge_get_product_sku' );

#1189058

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jelle,

Diego is unavailable at the moment so I will be answering here.

Could you let me know the context under which you are using this wc_sku shortcode ?

Thanks,
Shane