I have received a message from WordPress about a fatal error. It relates to a particular page in the backend in the WPML string translation plugin. I think a particular translation:
visit the page where the error was caught (xxxxxxxx/wp-admin/admin.php?page=wpml-translation-management%2Fmenu%2Ftranslations-queue.php&return_url=%2Fwp-admin%2Fpost.php%3Fpost%3D117195%26action%3Dedit%26lang%3Den%26message%3D6&job_id=3741&update_needed=1&trid=129987&language_code=fr)
It also says
Error Details ============= An error of type E_ERROR was caused in line 259 of the file /nas/content/live/mywebsite/wp-content/themes/babasouk/functions.php. Error message: Uncaught Error: Call to a member function get_stock_quantity() on null in /nas/content/live/mywebsite/wp-content/themes/mytheme/functions.php:259 Stack trace: #0 /nas/content/live/mywebsite/wp-includes/class-wp-hook.php(303): bbloomer_custom_get_availability_text('100 in stock', NULL)
#1 /nas/content/live/mywebsite/wp-includes/plugin.php(189): WP_Hook->apply_filters('100 in stock', Array)
#2 /nas/content/live/mywebsite/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(2082): apply_filters('woocommerce_get...', '100 in stock', Object(WC_Product_Variation))
#3 /nas/content/live/mywebsite/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(2058): WC_Product->get_availability_text()
#4 /nas/content/live/mywebsite/wp-content/plugins/woocommerce/includes/wc-template-functions.php(3512): WC_Product->get_availability()
#5 /nas/content/live/mywebsite/wp-content/plugins/woocommerce/includes/class-wc-product-variable.php(367): wc_get_stock_html(Object(W
In my PHP I echo get_stock_quantity()and it returns a value. I also tried echo of $product and returned everything. I disabled it because it is too much information. Website is here. https://babasoukstage.wpengine.com/shop/product-category/decor/moroccan-kilim-pillows/
Could the problem be the '' empty value I am declaring for translation? __( '', 'babasouk' );
My PHP is
function bbloomer_show_stock_shop() {
global $product;
echo wc_get_stock_html( $product );
}
// CHANGE STOCK MESSAGES
add_filter( 'woocommerce_get_availability_text', 'bbloomer_custom_get_availability_text', 99, 2 );
function bbloomer_custom_get_availability_text( $availability, $product ) {
global $product; // TO MAKE CATEGORY AVAILABLE
$stock = $product->get_stock_quantity(); //THIS IS LINE 259
//echo $product; does echo all product details when active
echo $stock;//test to see if stock quantity returned. Does display on category and product pages.
// OUTSIDE THE CATEGORY EXCLUSION SO THEY APPLY TO ALL
if ( !$product->is_in_stock() )$availability = __( 'Sorry, I am sold out!', 'babasouk' ); //OUT OF STOCK MESSAGE
if ( $product->is_in_stock() && ( $stock >= 2 ) )$availability = __( '', 'babasouk' ); //NO MESSAGE IF STOCK OVER 1
//EXCLUDE THESE CATEGORIES FOR 1 ITEM LEFT MESSAGE. IF THESE CATEGORIES MESSAGE IS BLANK.
if ( has_term( array( 'ORIGINAL ARTWORKS', 'OEUVRES ORIGINALES' ), 'product_cat' ) ) {
if ( $product->is_in_stock() && ( $stock == 1 ) )$availability = __( '', 'babasouk' ); //
} //IF NOT EXCLUDED CATEGORIES MESSAGE IS 'Only 1 Available!'
else if ( $product->is_in_stock() && ( $stock == 1 ) )$availability = __( 'Only 1 Available!', 'babasouk' );
return $availability;
}

所有评论(0)