I've been given a few lines of code by the developer of the plugin but I can't seem to fix the error that shows. We're attempting to prevent the user from adding an item to cart when the store is closed by removing the button altogether.
add_filter( 'woocommerce_is_purchasable', function($show_cart) {
global $product;
$seller_id = get_post_field('post_author', $product->get_id());
//print_r($seller);
if(dokan_is_store_open( $seller_id )) {
$show_cart = true;
} else {
$show_cart = false;
}
return $show_cart;
}, 1000);
This code is added into the child theme - functions.php in wordpress. The error warning that shows up is
Fatal error: Uncaught Error: Call to a member function get_id() on null in /home/customer/www/usku.com.au/public_html/wp-content/themes/hestia-pro-child/functions.php:819 Stack trace: #0 /home/customer/www/usku.com.au/public_html/wp-includes/class-wp-hook.php(294): {closure}(true) #1 /home/customer/www/usku.com.au/public_html/wp-includes/plugin.php(212): WP_Hook->apply_filters(true, Array) #2 /home/customer/www/usku.com.au/public_html/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-product.php(1543): apply_filters('woocommerce_is_...', true, Object(WC_Product_Simple)) #3 /home/customer/www/usku.com.au/public_html/wp-content/plugins/woocommerce/includes/class-wc-cart-session.php(131): WC_Product->is_purchasable() #4 /home/customer/www/usku.com.au/public_html/wp-content/plugins/woocommerce/includes/class-wc-cart.php(602): WC_Cart_Session->get_cart_from_session() #5 /home/customer/www/usku.com.au/public_html/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1478): WC_Cart->get_cart() #6 /home/customer/w in /home/customer/www/usku.com.au/public_html/wp-content/themes/hestia-pro-child/functions.php on line 819
Line 819 refers to this line specifically: $seller_id = get_post_field('post_author', $product->get_id());