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
Related
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.
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.
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.
I making a small site and decided to use Valitron library for the validation part of my site. I noticed there is no kind of "unique" method that returns whether a passed value already exists in the database or not. I quickly added this method, but not like it is recommended to do. I added this:
protected function validateUnique($field, $value, $table)
{
$model = new Model();
return $model->unique($table[0], $field, $value);
}
to the main Validator class. The thing is, it is working, but only with one field. If I use this on 2 or more fields in my validation proccess, I get this error
Fatal error: Uncaught exception 'RedBeanPHP\RedException' with message 'A database has already be specified for this key.' in C:\dev\htdocs\Shop\vendor\gabordemooij\redbean\RedBeanPHP\Facade.php:295 Stack trace: #0 C:\dev\htdocs\Shop\vendor\gabordemooij\redbean\RedBeanPHP\Facade.php(216): RedBeanPHP\Facade::addDatabase('default', 'mysql:host=127....', 'root', '', false) #1 C:\dev\htdocs\Shop\app\libs\Model.php(18): RedBeanPHP\Facade::setup('mysql:host=127....', 'root', '') #2 C:\dev\htdocs\Shop\vendor\vlucas\valitron\src\Valitron\Validator.php(429): Shop\libs\Model->__construct() #3 [internal function]: Valitron\Validator->validateUnique('email', 'email.example#g...', Array) #4 C:\dev\htdocs\Shop\vendor\vlucas\valitron\src\Valitron\Validator.php(885): call_user_func(Array, 'email', 'email.example#g...', Array) #5 C:\dev\htdocs\Shop\app\controllers\AuthController.php(68): Valitron\Validator->validate() #6 [internal function]: Shop\controllers\AuthController->postRegister() #7 C:\dev\htdocs\Shop\app\libs\Bootstrap.php(64): in C:\dev\htdocs\Shop\vendor\gabordemooij\redbean\RedBeanPHP\Facade.php on line 295
I work with RedBean as well as Valitron for the first time and I'm not able to say what causes the problem.
I got the same error.
A database has already be specified for this key. in /var/www/html...
I have already setup one database and want to connect another database then I used R::addDatabase() function to add new databse and R::selectDatabase() function to select that database.
code is
define('dsn2', 'pgsql:host=localhost;dbname=mydb';
R::addDatabase('DB2', dsn2, 'dbusers', 'dbpasss');
R::selectDatabase('DB2');
I am trying to create sample project in yii but I am having this problem while trying to run my code:
CHttpException
The system is unable to find the requested action "error". (C:\wamp\www\yii\framework\web\CController.php:484)
#0 C:\wamp\www\yii\framework\web\CController.php(271): CController->missingAction('error')
#1 C:\wamp\www\yii\framework\web\CWebApplication.php(276): CController->run('error')
#2 C:\wamp\www\yii\framework\base\CErrorHandler.php(310): CWebApplication->runController('site/error')
#3 C:\wamp\www\yii\framework\base\CErrorHandler.php(183): CErrorHandler->render('error', Array)
#4 C:\wamp\www\yii\framework\base\CErrorHandler.php(108): CErrorHandler->handleException(Object(CHttpException))
#5 C:\wamp\www\yii\framework\base\CApplication.php(713): CErrorHandler->handle(Object(CExceptionEvent))
#6 [internal function]: CApplication->handleException(Object(CHttpException))
#7 {main}
Can anyone tell me the reason ? As I think this is not the problem of my code.
An exception has occurred (most likely due to a bug or misconfiguration) and Yii attempted to run the error handler, which in this case is the error action on the site controller.
The error occurs because you do not have a site controller, or it does not have an error action.