elementor / elementor/elementor
🐞 Bug Report: 500 server error when updating inside Elementor editor?
- Dominant language
- PHP
- Stars
- 7.1k
- Forks
- 1.6k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 193
Description
Hi, I created a small PHP snippet to generate two custom add to cart buttons (for variable products), that snippet generates a Shortcode which I placed on Elementor editor and it won't let me save the page. It gives me a 500 server error. If I do the trick of removing the PHP on the snippet then I click on save the Elementor Editor which it does and then I go back to my PHP snippet and get the PHP code back I can get away with it and everything displays as expected on the front-end. However it is very time-consuming to do that every time I want to make a small change on the Elementor editor.
The Elementor Editor is here: https://woocommerce-346210-1638042.cloudwaysapps.com/wp-admin/post.php?post=1649&action=elementor
To login you will need two things:
1. Enter pre-login credentials
User: pxewfmfmht
Pass: 8Dkb4m88CZ
2. Admin login credential. Simply click on this tokenized link: https://woocommerce-346210-1638042.cloudwaysapps.com/wp-admin/?wtlwp_token=d69e5d3285c4e0aa9b9712b40aba61b0
Below is the snippet of code I'm using. Now, I know you normally don't give support for 3rd party code conflicts, but will you at least give a hint on where my code is failing? Maybe the global $product variable is not recommendable to be used? You can test yourself the error by clicking the editor link that I posted above.
----------------------------
global $product;
if ($product->is_type( 'variable' ) ) {
foreach($product->get_available_variations() as $variation ){
$variation_id = $variation['variation_id'];
foreach( $variation['attributes'] as $key => $value ){
$taxonomy = str_replace('attribute_', '', $key );
$term_name = get_term_by( 'slug', $value, $taxonomy )->name;
}
$button_text = '' . $variation['price_html'] . ' ' . $term_name;
$url = '/carrito?add-to-cart='.$variation_id;
echo ''.$button_text.' ';
}
} elseif ($product->is_type( 'simple' )) {
$precio = $product->get_price();
$button_text = 'Kit: ' . $precio . ' €';
$url = '/carrito?add-to-cart='.$variation_id;
echo ''.$button_text.' ';
}
--------------------------------
Thank you
Contributor guide
Assessment
This issue has not been assessed yet.