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, 10 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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, 10 months ago.

Assisted by: Shane.

Author
Posts
#1189078

Hi Shane,

No problem, yes of course. I need to display the SKU outside of the product page. There for I've found a function with shortcode, but this trowing an error like described earlier in the ticket. Toolset won't save my content template or view whit this code in my child theme's function.php. Is there a workaround available? Same thing whas happening with the function for the attributes Diego modified, but I'm not sure why this is happening.

#1189174

Shane
Supporter

Languages: English (English )

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

Hi Jelle,

I believe I know what the issue is, however i would need to test the fixes on the site ?

Would it be possible to provide me with access so that I can do this and then let you know what the fix is ?

Also could you send me an example page where the issue is ?

Looking forward to hearing from you.

Thanks,
Shane

#1189751

Shane
Supporter

Languages: English (English )

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

Hi Jelle,

Could you let me know which template you are using the shortcode in ? I want to ensure that i'm looking in the right place.

Thanks,
Shane

#1189760

Hi Shane,

I;m using the shortcode in Datasheet Child view, first th in the loop item section. I have removed the shortcode from functions.php to prefend Toolset from giving any errors. The code I have used and which gave the errors is:

function display_woo_sku() {
 
    global $product;
    return $product->get_sku();
 
}
add_shortcode( 'woo_sku', 'display_woo_sku' );

#1189817

Shane
Supporter

Languages: English (English )

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

Hi Jelle,

Try using this shortcode.

function display_woo_sku($atts) {
	// Attributes
	$atts = shortcode_atts(
		array(
			'id' => '',
		),
		$atts
	);

$product_id = $atts['id'];
if(empty($atts['id']) ){
$product_id = get_the_ID() ;
}
$sku = "Woocommerce is not active";
if ( class_exists( 'WooCommerce' ) ) {
    $product = wc_get_product($product_id);
    $sku = $product->get_sku();
}
    return $sku
 
}
add_shortcode( 'woo_sku', 'display_woo_sku' );

Please try this and let me know if it works. Also you will need to change your shortcode to [woo_sku id='[wpv-post-id]']

Thanks,
Shane

#1189842

Hi Shane,

Thanks. When I try so save the snippet an error returs:

Your PHP code changes were rolled back due to an error on line 120 of file wp-content/themes/Zephyr-child/functions.php. Please fix and try saving again.

syntax error, unexpected '}', expecting ';'

What should I do?

#1189944

Shane
Supporter

Languages: English (English )

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

Hi Jelle,

I forgot the semi colon on the return statement.

Replace this line
return $sku

with

return $sku;

This should fix it.

#1189956
Schermafdruk 2019-01-23 20.19.29.png

Hi Shane,

Thanks again. Looks like the snippet and shortcode are working, but again after modifying a content template, in this case: Loop item in Datasheet Child view, Toolset throws an error like shown in the image.

#1189998

Shane
Supporter

Languages: English (English )

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

Hi Jelle,

I checked on the template and it was saving fine from my end.

#1190019

Hi Shane,

I guess that’s because I’ve removed the snippet from functions.php. Does it also saves on your end with the snippet active in the child theme functions.php?

#1190475

Shane
Supporter

Languages: English (English )

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

Hi Jelle,

Could you let me know where this view is loaded on the frontend?

You can just send a link to the page.

I need to know this so that I can fully understand.

Thanks,
Shane

#1190528

Hi,

Please follow this link: hidden link

The field sku shows: [woo_sku id='57025'] this is because I removed the snippet from child theme's function.php in order to get the view saveable. With the snippet in functions.php the SKU shows up, but I'm not able to make modifications and save the view. In this case the red warning appears like I showed you in the screenshot. Thanks.

#1190556

Shane
Supporter

Languages: English (English )

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

Hi Jelle,

The issue was being caused by the get_sku() function that woocommerce uses. I was still able to get the sku from the product object without it.

So it should be fine now.

Thanks,
Shane

#1190558

Hi Shane,

Thanks. Is this normal behaviour and do I need to modify anything or did you do it for me?

#1190748

Shane
Supporter

Languages: English (English )

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

Hi Jelle,

I made the modification.

No this isn't normal, however the template does save even if it says cannot save. I tested this scenario and it did save but I still went ahead to debug and resolve it.

Thanks,
Shane