Woocommerce Add to cart function showing error - woocommerce

I am just using the below code. It was working fine but from today is shows error - "TypeError thrown wc_add_number_precision(): Argument #1 ($value) must be of type float, null given, called in /chroot/home/a23cc473/fdd76f6eaa.nxcli.net/html/wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 1955". Here is my code - WC()->cart->add_to_cart( 5 )
Can anyone please advise me why this error is showing

It's related with newest WC core, go and edit wc->includes->wc-core-functions.php row 1918 and replace it with older function:
new (not working) :
function wc_add_number_precision( float $value, bool $round = true ) {
old (working one) :
function wc_add_number_precision( $value, $round = true ) {
It's not best fix, but at least is working.

Related

wpallimport, run function 'dont_create_terms' only for specidied taxonomies

So, prefix that my coding level is practically equal to zero...
I'm using Wordpress with Wp All Import plugin, and i have this code to prevent wpallimport to create new categories/taxonomies etc.
function dont_create_terms( $term_into, $tx_name ) {
// Check if term exists, checking both top-level and child
// taxonomy terms.
$term = empty($term_into['parent']) ? term_exists( $term_into['name'], $tx_name, 0 ) : term_exists( $term_into['name'], $tx_name, $term_into['parent'] );
// Don't allow WP All Import to create the term if it doesn't
// already exist.
if ( empty($term) and !is_wp_error($term) ) {
return false;
}
// If the term already exists assign it.
return $term_into;
}
add_filter( 'pmxi_single_category', 'dont_create_terms', 10, 2 );
Now, as specified in the title, i have to run this code only for certain taxonomies...
I have tried multiple solutions, for last i tried to add this line
if ($tx_name == 'taxonomyname') {
like here
function dont_create_terms( $term_into, $tx_name ) {
// Check if term exists, checking both top-level and child
// taxonomy terms.
$term = empty($term_into['parent']) ? term_exists( $term_into['name'], $tx_name, 0 ) : term_exists( $term_into['name'], $tx_name, $term_into['parent'] );
if ($tx_name == 'taxonomyname') {
// Don't allow WP All Import to create the term if it doesn't
// already exist.
if ( empty($term) and !is_wp_error($term) ) {
return false;
}
// If the term already exists assign it.
return $term_into;
}
add_filter( 'pmxi_single_category', 'dont_create_terms', 10, 2 );
but everytime nothing appens.
Any help is really appreciated, thanks to everyone in advance
Edit:
Solution found
function dont_create_terms( $term_into ) {
// Check if term exists, checking both top-level and child
// taxonomy terms.
$term = empty($term_into['parent']) ? term_exists( $term_into['name'], $tx_name, 0 ) : term_exists( $term_into['name'], $tx_name, $term_into['parent'] );
if ( $tx_name == 'taxonomy_name' ){
// Don't allow WP All Import to create the term if it doesn't
// already exist.
if ( empty($term) and !is_wp_error($term) ) {
return false;
}
// If the term already exists assign it.
return $term_into;
}
add_filter( 'pmxi_single_category', 'dont_create_terms', 10, 2 );
And than call the function:
[dont_create_terms({yourxmldata[1]})]
Edit 2
It only works with single taxonomies, if the taxonomies contain multiple values it will not work
So again, if you have any suggestions you are welcome
The right way to do this would be writing your our custom function as shown here: https://www.wpallimport.com/documentation/code-snippets/#reference-taxonomy-terms-by-custom-id
However, although it is not elegant at all, I have found a different solution that could work for some, which involves wp-all-import's [foreach()] function.
It is not flexible as it requires that you add the max amount of values possible in your file (e.g 6 values tops in this example):
[foreach( {ParentNode/CategoryNode} )] {#id} > {Value1} |
{#id} > {Value[2]} | {#id} > {Value[3]} | {#id} > {Value[4]} |
{#id} > {Value[5]} | {#id} > {Value[6]} | [endforeach]
Where {ParentNode/CategoryNode} + #id + Value represent this portion of the xml file:
<ParentNode>
<CategoryNode id="this-cat-id">
<Value>Your value here</Value>
</CategoryNode>
</ParentNode>
Important: This will generate this error log while importing, every time it tries to import a value that does not exist, but the import will still work:
WARNING: It is necessary to assign a name to this term.
Important:
(1) In the import settings, you will need to go to 'Taxonomies, Categories, Tags', and select 'An element in my file contains the entire hierarchy...'.
(2) Then, check 'Separate hierarchy groups via symbol'.
(3) Do not check 'Only assign Your-cat-name-goes-here to the bottom level term in the hierarchy'
Here is how I set it up....
Screenshot WPAllImport
Hope this helps newcomers!

Wordpress/Woocommerce - blank 'new post' admin page, can't create posts

I have had the store for years, but never added blog posts, so I am not sure how long this has been broken - it may have been from the very first version.
I am now looking at adding a blog to the store but selected 'new post' just gives a blank screen - the console in chrome shows the following errors.
> JQMIGRATE: Migrate is installed, version 1.4.1
data.min.js?ver=4.2.0:1 Uncaught TypeError: Object(...) is not a function
at Module.308 (data.min.js?ver=4.2.0:1)
at r (data.min.js?ver=4.2.0:1)
at wp.data.0 (data.min.js?ver=4.2.0:1)
at data.min.js?ver=4.2.0:1
post-new.php:2018 Uncaught TypeError: Cannot read property 'use' of undefined
at post-new.php:2018
at post-new.php:2020
The code is so abstracted that I am not sure what it is actually doing - but all the code is in wp-includes/js/dist/
And the bit of code throwing the error looks like this (the second line is highlighted as failing).
var A = {
reducer: Object(f.flowRight)([S("reducerKey"), S("selectorName")])(function() {
var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : new m.a
, e = arguments.length > 1 ? arguments[1] : void 0;
switch (e.type) {
case "START_RESOLUTION":
case "FINISH_RESOLUTION":
var r = "START_RESOLUTION" === e.type
, n = new m.a(t);
return n.set(e.args, r),
n;
case "INVALIDATE_RESOLUTION":
var o = new m.a(t);
return o.delete(e.args),
o
}
return t
}),
I have tried this in chrome and edge, both get exactly the same result - same error, but a bit less informative in the edge console.
It seems to be a guttenburg/block editor issue, the old classic editor, can be enabled using this plug in
https://wordpress.org/plugins/classic-editor/

I have successfully enlisted a user in cohort via core_cohort_add_cohort_members but getting a warning

I have successfuly enlisted a user in moodle cohort using core_cohort_add_cohort_members but i am getting a warning in response.Can anybody help me remoce this warning.
Here is the warning i get.
{"warnings":[]}
Here is my code
$fname = 'core_cohort_add_cohort_members';
/// Paramètres
$member = new stdClass();
$member->cohorttype[type]='id';
$member->cohorttype[value]=2;
$member->usertype[type]='id';
$member->usertype[value]=8;
$members = array($member);
$par = array('members' => $members);
$rest_format = 'json';
$Serve_Url = 'localhost/moodle' . '/webservice/rest/server.php'. '?wstoken=' . '72f102312fff135cbb4a301d9c7839ae' .'&wsfunction='. $fname;
require_once('curl.inc');
$Rest_format = ($rest_format == 'json') ? '&moodlewsrestformat=' . $rest_format : '';
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$rep = $curl->post($Serve_Url.$Rest_format, $par);
dpm($rep);
The warnings array is empty in your example reply.
If you want to detect this more verbosely, you can always just json_decode() the reply. You should see an empty array there.
So I think it's working just as you wanted.
Turn the keys into strings i.e
$member->cohorttype["type"]='id';
$member->cohorttype["value"]=2;
$member->usertype["type"]='id';
$member->usertype["value"]=8;
Mainly because newer versions of PHP may cause real exceptions because of
unidentified variables(type and value)
That aside as Sebastian Berm stated empty warnings array means no problem

Call to undefined method stdClass::count() in drupal 7

I have an issue with a count function in drupal 7.
Code is :
$sql = "select count(Status) from TB_Aanmeldingen where (Status= 'Ja' or Status='Ja, met kleine') and ID_Wedstrijd = :match";
$args = array(':match' => $match);
$row = db_query($sql, $args)->fetchObject();
$aantal = $row->count(Status);
Error message:
Call to undefined method stdClass::count()
Any help is very much appreciated!
I'm not sure what you're trying to do with:
$aantal = $row->count(Status);
Do a print_r or var_dump of the $row object, and you'll see what the structure is. db_query returns a DatabaseStatementInterface, and you're getting an object from it. But the object doesn't have a function you're trying to call.
Instead, debug, print out, and debug the value of $row, and get the value you're looking for.
Also, look into db_select. It's better to use that then db_query.
https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_select/7

Drupal filter is not working properly

I'm not sure how to ask it, so if you need anymore additional information, please ask for it!
Situation
I've got a website in three languages. I got a lot of customer cases online each connected to a sector (depending in which sector they belong). Each sector and reference has it's own unique nid.
In my template.php it's stated like this:
if ('sector' == $vars['node']->type) {
$lang = '/'.$vars['language'].'/';
$key_path = $_SERVER['REQUEST_URI'];
$key_path = substr_count($key_path, $lang) ? substr($key_path, strlen($lang)) : $key_path;
if (strpos($key_path, '?')) $key_path = substr_replace($key_path, '', strpos($key_path, '?'));
if (strpos($key_path, 'sectors-references') === 0) {
$view = views_get_view('references');
if (!empty($view)) {
$view->set_arguments((int)$vars['node']->nid);
$vars['content']['suffix'] = $view->render();
}
}
}
And yet, every sector shows me the same references... What do I have to change to get the correct reference under the right sector?
Usually arguments are passed to set_arguments using an array, if you pass a non-array the argument will probably be ignored which is why you're always getting the same result. Try:
$view->set_arguments(array((int)$vars['node']->nid));

Resources