On a specific template in Astra Theme, I try to display the price of the current product.
To do so, I put à PHP code in the functions.php file to create à shortcode.
Error message when trying to save the publication : Update failed
When trying to reload the page, or access it again from the dashboard; I got the lightgray screen with the critical error message.
If I disable the code, save the page with the sort code in it, then reactivate the code in the function file, here is what happening :
The dashboard, and the frontend are working fine, the shortcode works and display the price on the frontend, but the page in the backend where I put the shortcode is broken.
Here is the php code I put in function.php :
add_shortcode( 'avv-woo-price', function () {
$product = wc_get_product(get_the_ID());
$thePrice = $product->get_price_html();
return $thePrice;
} );
Could you please help me find what I miss ?
Thank you very much !
]]>We have a custom snippet on our site to format prices with and without taxes and whenever we enable that snippet, your search plugin throws the following fatal error.
Fatal error: Uncaught Error: Call to a member function get_price() on null in /home/customer/www/abcd.com/public_html/wp-content/plugins/woocommerce/includes/wc-product-functions.php:1047 Stack trace: #0 /home/customer/www/abcd.com/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(446) : eval()'d code(6): wc_get_price_excluding_tax(NULL) #1 /home/customer/www/abcd.com/public_html/wp-includes/class-wp-hook.php(287): pm_price_formatting('<span class="wo...', NULL) #2 /home/customer/www/abcd.com/public_html/wp-includes/plugin.php(212): WP_Hook->apply_filters('<span class="wo...', Array) #3 /home/customer/www/abcd.com/public_html/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(1803): apply_filters('woocommerce_get...', '<span class="wo...', Object(WC_Product_Simple)) #4 /home/customer/www/abcd.com/public_html/wp-content/plugins/advanced-woo-search/includes/class-aws-search.php(572): WC_Product->get_price_html() #5 /home/custom in /home/customer/www/abcd.com/public_html/wp-content/plugins/woocommerce/includes/wc-product-functions.php on line 1047
Here’s the custom snippet:
add_filter( 'woocommerce_get_price_html', 'pm_price_formatting', 99, 2 );
function pm_price_formatting ( $price, $product ){
global $product;
$currency = esc_attr( get_woocommerce_currency( ) ); // Get the currency code.
$price_excl_tax = number_format (wc_get_price_excluding_tax( $product ), 2); // price without VAT
$price_incl_tax = number_format (wc_get_price_including_tax( $product ), 2); // price with VAT
$int = wc_get_price_decimals();
$price = '<span class="price-without-tax">'.esc_attr( get_woocommerce_currency_symbol( $currency )) .$price_excl_tax.' (Exc. VAT)'.'</span>'.' | '.'<span class="price-with-tax">'.esc_attr( get_woocommerce_currency_symbol( $currency )) . $price_incl_tax.' (Inc. VAT)'.'</span>';
return $price;
}
Could you please let us know how to get this issue rectified?
Many thanks in advance
]]>I have an issue with how the products are rendered in an e-mail when using the woocommerce shortcode. When I preview the newsletter in WP when creating it, it looks OK: https://ibb.co/xFgfXnm
However, when I send the e-mail, it doesn’t take into consideration the imagesize=”80,160″ element of the shortcode. It renders the pictures in full size: https://www.loom.com/share/22a623bd05194922b6ca94186144a0c5.
Can you please check?
Also another question – it is displaying even products that are scheduled (not published yet). Is it possible to limit the shortcode to send out only published products and NOT scheduled/unpublished ones?
Thank you!
]]>Is there a way to display regular price in the improved way of displaying products in e-mails?
Talking about this: https://tribulant.com/docs/wordpress-mailing-list-plugin/11518/newsletters-woocommerce-products-in-newsletters/
The showprice attribute only displays sale price (current price). I’d need to show both.
Thank you!
]]>This is the function:
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);
add_filter( 'woocommerce_product_get_price', 'return_custom_price', 10, 2 );
add_filter( 'woocommerce_product_variation_get_price', 'return_custom_price', 10, 2 );
add_filter( 'woocommerce_product_get_regular_price', 'return_custom_price', 10, 2 );
add_filter( 'woocommerce_product_get_sale_price', 'return_custom_price', 10, 2 );
function return_custom_price($price, $product) {
global $post, $blog_id;
$post_id = $value['product_id'];
$price = get_post_meta($post->ID, '_regular_price', true);
$ssivata = 7.93;
$tax = 122/100;
$shipping = 6.5;
//calcola prezzo di fabbrica
$price = $price - $ssivata;
$price = $price / $tax;
//calcolo del prezzo
$price = $price + $shipping;
$price = $price*$tax;
return $price;
}
]]>I would like to make it so i don’t have to manually change this every time we make a change to a products pricing.
I have come to think the easiest and best way to do this is just to display the cheapest product in this categories price. I have tried to use the add to cart short code and hide the add to cart button but have had no luck.
Any insight on how to go about this would be great. Thanks so very much in advance.
Example of a page I am trying to use this on:
https://www.camelbackdisplays.com/newsite/?page_id=4838
https://www.ads-software.com/plugins/woocommerce/
]]>For the life of me I can’t seem to display the simple product price in my theme. Most of the time I use this function:
<?php echo $product->get_price_html(); ?>
This seems to be the crème de la crème and everyone must be satisfied with this solution as I can’t find anything on the net otherwise :-). However, the problem with this is that it echos both the sale price and the regular price within it’s predefined HTML code layout.
I want to be able to echo the sale price and regular price separately so I have more flexibility in designing themes.
Looking into this function I see the following is used in the WC product variation class:
woocommerce_price( $this->regular_price )
and
woocommerce_price( $this->sale_price)
These sale_price and regular_price variables seem to be exactly want I want. But how do I display these within the theme?
I’ve tried woocommerce_price( $product_id->regular_price )
with no luck.
Can you please help or send over a link a any documentation which explain this?
Many thanks,
Steven