Include PHP file in Woocommerce template - php

I'm customising the Woocommerce content-single-product.php and want to add a custom template file for the sidebar.
so far I've tried:
<?php require get_stylesheet_directory() . '/layout/page-sidebar.php'; ?>
This works elsewhere in my theme but not on Woocommerce templates where it gives an error.
Fatal error: Uncaught Error: Call to a member function get_price_html() on null in /Applications/MAMP/htdocs/stage/wp-content/themes/bright-theme/woocommerce/single-product/price.php:25 Stack trace: #0 /Applications/MAMP/htdocs/stage/wp-content/plugins/woocommerce/includes/wc-core-functions.php(249): include() #1 /Applications/MAMP/htdocs/stage/wp-content/plugins/woocommerce/includes/wc-template-functions.php(1524): wc_get_template('single-product/...') #2 /Applications/MAMP/htdocs/stage/wp-includes/class-wp-hook.php(288): woocommerce_template_single_price('') #3 /Applications/MAMP/htdocs/stage/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(NULL, Array) #4 /Applications/MAMP/htdocs/stage/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #5 /Applications/MAMP/htdocs/stage/wp-content/themes/bright-theme/woocommerce/content-single-product.php(54): do_action('woocommerce_sin...') #6 /Applications/MAMP/htdocs/stage/wp-includes/template.php(724): require('/Applications/M...') #7 /Applications/MAMP/htdocs/stage/ in /Applications/MAMP/htdocs/stage/wp-content/themes/bright-theme/woocommerce/single-product/price.php on line 25

get_price_html() has to be called on an instance of $product. Maybe there is no product on your page and thats why it is null - which is again why your error says called get_price_html() on null.
As your're on a product there should be a product loaded, so you can try finding the product by calling global $product; before the method is called.
The error says that the method was called on line 25 - is this the line of the import?
We would need some more surrounding code to really track down the issue.

It was a query in my template file I was calling.
<?php endwhile; wp_reset_query(); ?>
Fixed the problem.

Related

Empty Woocommerce cart when page is loaded

Im using Woocommerce with Astra theme and I'm trying to add a function that clears the user's cart every time the page is reloaded, even for logged users. I've already tried many solutions I found here but no one of them work.
Im using a plugin called "Woocommerce assinaturas" (Brazilian name) which is used to prevent non-member users from accessing the pages and somehow it is conflicting with any code I add in the "functions.php" file from my theme...
So what i need is: a code snippet (that is not 10 years old like most others I found here) that empty the user's cart every time the page is reloaded and doesnt conflict with the plugin im using.
Would be glad if I could manage to do the plugin function without it.
The code im trying to add to "functions.php":
add_action( 'template_redirect', 'custom_empty_cart' );
function custom_empty_cart() {
if ( ! ( is_cart() || is_checkout() ) && ! WC()->cart->is_empty() ) {
WC()->cart->wc_empty_cart( true );
}
The error:
Uncaught TypeError: array_reverse(): Argument #1 ($array) must be of type array, bool given in wp-content/plugins/woocommerce-assinaturas/woocommerce-assinaturas.php:978
Stack trace:
#0 wp-content/plugins/woocommerce-assinaturas/woocommerce-assinaturas.php(978): array_reverse(false)
#1 wp-content/plugins/woocommerce-assinaturas/woocommerce-assinaturas.php(1074): verificar_assinatura_ativa(Array)
#2 wp-includes/class-wp-hook.php(308): plugin_assinaturas_template_redirect_fn('')
#3 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
#4 wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#5 wp-includes/template-loader.php(13): do_action('template_redire...')
#6 wp-blog-header.php(19): require_once('wp-inc...')
#7 index.php(17): require('wp-blo...')
#8 {main}
thrown

Magento 1.9.3 Uncaught Error: Call to a member function getMethodInstance() on boolean Payment/Model/Observer.php

I am using Magento version 1.9.3 and payment gateway from CCAvenue.
At the time of checkout and sucessfull making the payment, when returning back to the website from CCAvenue. I am getting this error instead of successfull payment:
Fatal error: Uncaught Error: Call to a member function getMethodInstance() on boolean in app/code/core/Mage/Payment/Model/Observer.php:46 Stack trace:
#0 app/code/core/Mage/Core/Model/App.php(1358): Mage_Payment_Model_Observer->salesOrderBeforeSave(Object(Varien_Event_Observer))
#1 app/code/core/Mage/Core/Model/App.php(1337): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Payment_Model_Observer), 'salesOrderBefor...', Object(Varien_Event_Observer))
#2 app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('sales_order_sav...', Array)
#3 app/code/core/Mage/Core/Model/Abstract.php(391): Mage::dispatchEvent('sales_order_sav...', Array)
#4 app/code/core/Mage/Sales/Model/Order.php(2117): Mage_Core_Model_Abstract->_beforeSave()
#5 app/code/core/Mage/Core/Model/Abstract.php(316): Mage_Sales_Model_Order-> in app/code/core/Mage/Payment/Model/Observer.php on line 46
So far, I googled for solutions and tried couple of things like below:
$payment = $order->getPayment();
if(!isset($payment)) {
return $this->_redirect('checkout/cart');
}
With this solution, I am able to return to the checkout/cart but with the message of invalid access. Whereas the order is successfully done and the payment has deduction applied in all the cases.
I have also check the log but there is nothing that I can trace and rectify, FYI, here is the log relevant to it:
Stack trace:
#0 app/code/core/Mage/Core/Model/App.php(1358): Mage_Payment_Model_Observer->salesOrderBeforeSave(Object(Varien_Event_Observer))
#1 app/code/core/Mage/Core/Model/App.php(1337): Mage_Core_Model_App->_callObserverMethod(Object(Mage_Payment_Model_Observer), 'salesOrderBefor...', Object(Varien_Event_Observer))
#2 app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('sales_order_sav...', Array)
#3 app/code/core/Mage/Core/Model/Abstract.php(391): Mage::dispatchEvent('sales_order_sav...', Array)
#4 app/code/core/Mage/Sales/Model/Order.php(2117): Mage_Core_Model_Abstract->_beforeSave()
#5 app/code/core/Mage/Core/Model/Abstract.php(316): Mage_Sales_Model_Order-> in app/code/core/Mage/Payment/Model/Observer.php on line 46
This happens when order object is not loaded correctly.
In this case "order id" from session is missing while loading order object.
In CcavenuepayController.php, response handler function
search for
$order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
Replace with
$order = Mage::getModel('sales/order')->loadByIncrementId($response_array['order_id']);
We are replacing session order id with ccavenue response order id.

Fatal error: Uncaught Error: Call to undefined method stdClass::option();

**Fatal error: Uncaught Error: Call to undefined method stdClass::option() in
C:\xampp\htdocs\newtest\wordpress\wp-content\plugins\theme_support_meson\includes\helpers\taxonomies.php:19
Stack trace: #0
C:\xampp\htdocs\newtest\wordpress\wp-content\plugins\theme_support_meson\includes\loader.php(55):
Bunch_Taxonomies->__construct() #1
C:\xampp\htdocs\newtest\wordpress\wp-content\plugins\theme_support_meson\includes\loader.php(77):
_load_plugins_class('taxonomies', 'helpers', false) #2 C:\xampp\htdocs\newtest\wordpress\wp-includes\class-wp-hook.php(286):
_bunch_plugin_init('') #3 C:\xampp\htdocs\newtest\wordpress\wp-includes\class-wp-hook.php(310):
WP_Hook->apply_filters(NULL, Array) #4
C:\xampp\htdocs\newtest\wordpress\wp-includes\plugin.php(465):
WP_Hook->do_action(Array) #5
C:\xampp\htdocs\newtest\wordpress\wp-settings.php(505):
do_action('init') #6
C:\xampp\htdocs\newtest\wordpress\wp-config.php(90):
require_once('C:\\xampp\\htdocs...') #7
C:\xampp\htdocs\newtest\wordpress\wp-load.php(37):
require_once('C:\\xampp\\htdocs.. in
C:\xampp\htdocs\newtest\wordpress\wp-content\plugins\theme_support_meson\includes\helpers\taxonomies.php
on line 19**
This Error occurs when I am including new theme in my WordPress account. That time I am using meson theme and try to include new theme and suddenly this error occurs. so guide me on what to do for solving this.
Deactivate all plugins associated with the last theme, I can see that the error caused by theme_support_meson plugin so make sure to deactivate it then delete it.

How to add custom function ot User.php in MediaWiki?

I added the following custom function to User.php:
public function isUpgraded() {
return true;
}
and the following in my Foreground.skin.php which is my skin/theme for the wiki to simply access the value that the function returns:
$isUpgraded= $wgUser->isUpgraded();
but I get the following exception:
Fatal error: Uncaught Error: Call to undefined method User::isUpgraded() in /home/siteX/public_html/siteX.com/wiki/skins/foreground/Foreground.skin.php:106 Stack trace: #0 /home/siteX/public_html/siteX.com/wiki/includes/skins/SkinTemplate.php(251): foregroundTemplate->execute() #1 /home/siteX/public_html/siteX.com/wiki/includes/OutputPage.php(2388): SkinTemplate->outputPage() #2 /home/siteX/public_html/siteX.com/wiki/includes/exception/MWExceptionRenderer.php(135): OutputPage->output() #3 /home/siteX/public_html/siteX.com/wiki/includes/exception/MWExceptionRenderer.php(54): MWExceptionRenderer::reportHTML(Object(Error)) #4 /home/siteX/public_html/siteX.com/wiki/includes/exception/MWExceptionHandler.php(75): MWExceptionRenderer::output(Object(Error), 2) #5 /home/siteX/public_html/siteX.com/wiki/includes/exception/MWExceptionHandler.php(149): MWExceptionHandler::report(Object(Error)) #6 /home/siteX/public_html/dev. in /home/siteX/public_html/siteX.com/wiki/skins/foreground/Foreground.skin.php on line 106
Do I need to register the custom function in some other file in order for it to work? It might be worth mentioning that the code worked in MediaWiki 1.23 but I recently updated to 1.31 and can't get the following piece of code to work.

Zf2 "The iterator class does not exist" on Session\Container definition

Sometimes on my website (ZendFramework2), I get an error when setting a session variable.
The error:
PHP Fatal error: Uncaught exception 'Zend\\Stdlib\\Exception\\InvalidArgumentException' with message 'The iterator class does not exist' in /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php:374
Stack trace:
#0 /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php(414): Zend\\Stdlib\\ArrayObject\\PhpReferenceCompatibility->setIteratorClass(NULL)
#1 [internal function]: Zend\\Stdlib\\ArrayObject\\PhpReferenceCompatibility->unserialize('a:4:{s:7:"stora...')
#2 /MySite/vendor/zendframework/zendframework/library/Zend/Session/SessionManager.php(95): session_start()
#3 /MySite/vendor/zendframework/zendframework/library/Zend/Session/AbstractContainer.php(78): Zend\\Session\\SessionManager->start()
#4 /MySite/module/Application/Module.php(97): Zend\\Session\\AbstractContainer->__construct('site')
#5 [internal function]: Application\\Module->onBootstrap(Object(Zend\\Mvc\\MvcEvent))
#6 /MySite/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php on line 374
Code Module.php line 97 :
$s_site = new \Zend\Session\Container('site');
I try but I can not find why. Do you have any idea? Need more informations?
Thank you.
The is a result of the setIteratorClass method in ArrayObject/PhpReferenceCompatibility being passed a null $class argument. I'm not sure why it sometimes gets a null, but the way I fixed it in my case was to set the iterator class as 'ArrayIterator' when passed a null object, like this:
if (!isset($class)) {
$class = 'ArrayIterator';
}
In the latest zf2 version, the ArrayObject/PhpReferenceCompatibility class has been removed, so please make the change in stdlib/ArrayObject.php.

Categories