fahadmahmood8/stock-locations-for-woocommerce

Issue with Cache Enabler due to $product_id being string and not integer

Closed this issue · 1 comments

The issue I am facing is that with Cache Enabler when the stock is updated by SLW
I am getting an error saying:

Call to a member function get_id() on string

Here is where that code is being called:
https://github.com/keycdn/cache-enabler/blob/master/inc/cache_enabler.class.php#L1572-L1575

Back tracing that I can see it is coming from here:

	if ( $product->is_type( 'variation' ) ) {
		do_action( 'woocommerce_variation_set_stock_status', $product_id, $status, $product );
	} else {
		do_action( 'woocommerce_product_set_stock_status', $product_id, $status, $product );
	}

Source: src/helpers/helper-slw-product.php#L105-L109
This code was added from #120

I have added the following to just before that code on line 100 to see if it resolves the issue. Any idea though why $product_id would be a string instead of an integer?

$product_id = (int) $product_id;

Here is my stacktrace if someone else can see something I missed:

Error: Call to a member function get_id() on string
#49 /wp-content/plugins/cache-enabler/inc/cache_enabler.class.php(1575): Cache_Enabler::on_woocommerce_stock_update
#48 /wp-includes/class-wp-hook.php(310): WP_Hook::apply_filters
#47 /wp-includes/class-wp-hook.php(332): WP_Hook::do_action
#46 /wp-includes/plugin.php(517): do_action
#45 /wp-content/plugins/stock-locations-for-woocommerce/src/helpers/helper-slw-product.php(106): SLW\SRC\Helpers\SlwProductHelper::call_wc_product_stock_status_action
#44 /wp-content/plugins/stock-locations-for-woocommerce/src/helpers/helper-slw-product.php(66): SLW\SRC\Helpers\SlwProductHelper::update_wc_stock_status
#43 /wp-content/plugins/stock-locations-for-woocommerce/src/helpers/helper-slw-product.php(44): SLW\SRC\Helpers\SlwProductHelper::update_wc_stock_status
#42 /wp-content/plugins/stock-locations-for-woocommerce/src/helpers/helper-slw-frontend.php(47): SLW\SRC\Helpers\SlwFrontendHelper::get_all_product_stock_locations_for_selection
#41 /wp-content/plugins/stock-locations-for-woocommerce/src/classes/frontend/class-slw-frontend-product.php(61): SLW\SRC\Classes\Frontend\SlwFrontendProduct::location_select_input
#40 /wp-content/plugins/stock-locations-for-woocommerce/src/classes/frontend/class-slw-frontend-product.php(243): SLW\SRC\Classes\Frontend\SlwFrontendProduct::variable_location_select
#39 /wp-includes/class-wp-hook.php(308): WP_Hook::apply_filters
#38 /wp-includes/class-wp-hook.php(332): WP_Hook::do_action
#37 /wp-includes/plugin.php(517): do_action
#36 /wp-content/plugins/woocommerce/templates/single-product/add-to-cart/variable.php(71): include
#35 /wp-content/plugins/woocommerce/includes/wc-core-functions.php(345): wc_get_template
#34 /wp-content/plugins/woocommerce/includes/wc-template-functions.php(1742): woocommerce_variable_add_to_cart
#33 /wp-includes/class-wp-hook.php(308): WP_Hook::apply_filters
#32 /wp-includes/class-wp-hook.php(332): WP_Hook::do_action
#31 /wp-includes/plugin.php(517): do_action
#30 /wp-content/plugins/woocommerce/includes/wc-template-functions.php(1688): woocommerce_template_single_add_to_cart
#29 /wp-content/plugins/elementor-pro/modules/woocommerce/widgets/product-add-to-cart.php(48): ElementorPro\Modules\Woocommerce\Widgets\Product_Add_To_Cart::render
#28 /wp-content/plugins/elementor/includes/base/controls-stack.php(2266): Elementor\Controls_Stack::render_by_mode
#27 /wp-content/plugins/elementor/includes/base/widget-base.php(609): Elementor\Widget_Base::render_content
#26 /wp-content/plugins/elementor/includes/base/widget-base.php(750): Elementor\Widget_Base::print_content
#25 /wp-content/plugins/elementor/includes/base/element-base.php(449): Elementor\Element_Base::print_element
#24 /wp-content/plugins/elementor/includes/base/element-base.php(1348): Elementor\Element_Base::print_content
#23 /wp-content/plugins/elementor/includes/base/element-base.php(449): Elementor\Element_Base::print_element
#22 /wp-content/plugins/elementor/includes/base/element-base.php(1348): Elementor\Element_Base::print_content
#21 /wp-content/plugins/elementor/includes/base/element-base.php(449): Elementor\Element_Base::print_element
#20 /wp-content/plugins/elementor/includes/base/element-base.php(1348): Elementor\Element_Base::print_content
#19 /wp-content/plugins/elementor/includes/base/element-base.php(449): Elementor\Element_Base::print_element
#18 /wp-content/plugins/elementor/includes/base/element-base.php(1348): Elementor\Element_Base::print_content
#17 /wp-content/plugins/elementor/includes/base/element-base.php(449): Elementor\Element_Base::print_element
#16 /wp-content/plugins/elementor/core/base/document.php(1669): Elementor\Core\Base\Document::print_elements
#15 /wp-content/plugins/elementor-pro/modules/theme-builder/documents/theme-document.php(417): ElementorPro\Modules\ThemeBuilder\Documents\Theme_Document::print_elements_with_wrapper
#14 /wp-content/plugins/elementor/includes/frontend.php(1153): Elementor\Frontend::get_builder_content
#13 /wp-content/plugins/elementor/core/base/document.php(1144): Elementor\Core\Base\Document::get_content
#12 /wp-content/plugins/elementor/modules/library/documents/library-document.php(76): Elementor\Modules\Library\Documents\Library_Document::get_content
#11 /wp-content/plugins/elementor-pro/modules/theme-builder/documents/theme-document.php(157): ElementorPro\Modules\ThemeBuilder\Documents\Theme_Document::get_content
#10 /wp-content/plugins/elementor-pro/modules/theme-builder/documents/theme-document.php(172): ElementorPro\Modules\ThemeBuilder\Documents\Theme_Document::print_content
#9 /wp-content/plugins/elementor-pro/modules/theme-builder/documents/single-base.php(93): ElementorPro\Modules\ThemeBuilder\Documents\Single_Base::print_content
#8 /wp-content/plugins/elementor-pro/modules/woocommerce/documents/product.php(133): ElementorPro\Modules\Woocommerce\Documents\Product::print_content
#7 /wp-content/plugins/elementor-pro/modules/theme-builder/classes/locations-manager.php(315): ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager::do_location
#6 /wp-content/plugins/elementor-pro/modules/theme-builder/classes/locations-manager.php(191): ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager::ElementorPro\Modules\ThemeBuilder\Classes\{closure}
#5 [internal](0): call_user_func
#4 /wp-content/plugins/elementor/modules/page-templates/module.php(207): Elementor\Modules\PageTemplates\Module::print_content
#3 /wp-content/plugins/elementor/modules/page-templates/templates/header-footer.php(19): include
#2 /wp-includes/template-loader.php(106): require_once
#1 /wp-blog-header.php(19): require
#0 /index.php(17): null

I have added this fix, thank you so much.