WooCommerce API, Variant Sku breaks import - woocommerce

I am importing products with Variations and each variation having its own SKU. However if I include a 'sku' with a Variation, it does not add them, it adds one Variation as 'default value' and not the individual ones. If I exclude the 'sku' field then it works as expected. Yet WooCommerce documentation shows that Variants have a field of 'sku'.
This is what I am sending (With the PHP api handler):
[0] => Array
(
[sku] => BH2057A
[regular_price] => 2.99
[stock_quantity] => 29
[in_stock] => 1
[managing_stock] => 1
[attributes] => Array
(
[0] => Array
(
[name] => Alphabet
[option] => A
)
)
)
This is the variant for 'A', it goes to 'Z'. The attribute is added on the product fine. As I say this works when I do not include the sku line, but breaks when I include it.
Anyone know whats wrong?

Related

get_the_category() wordpress function stopped working after updating core version

As the title says - i have a single.php template which gets the category of the current post assigned.
$cat_post = get_the_category();
That function returns the category which is assigned to the post. After upgrading from 4.0.24 to 4.9.7 it stopped working. The only thing that comes to my mind is that the function is not supported but i haven't found something about this.
Any ideas?
you can use this
//get category
$category = get_the_category(get_the_ID());
//the above code will return an Array
Array
(
[0] => WP_Term Object
(
[term_id] => 2
[name] => video
[slug] => video
[term_group] => 0
[term_taxonomy_id] => 2
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 1
[filter] => raw
[cat_ID] => 2
[category_count] => 1
[category_description] =>
[cat_name] => video
[category_nicename] => video
[category_parent] => 0
)
)
// you can access this array like this
$catID = $category[0]->term_id;
//for term id
$catName = $category[0]->name;
//for category name
I think you are trying to get a category from the current post which is the custom post type.
As per the documentation of the following function, it doesn't work for the custom post type. You can see it on the link below.
Click here to see the Code Reference
For custom post type, you can use get_the_terms() method. Here is the link of the Code Reference of the function.

Square returning error with WooCommerce

I've installed the WooCommerce Square plugin to enable payments to our Square account but I get this error at the checkout when trying to pay with a credit card:
Array(
[0] => stdClass Object
(
[category] => INVALID_REQUEST_ERROR
[code] => MISSING_REQUIRED_PARAMETER
[detail] => Missing required parameter.
[field] => card_nonce
)
)
Any ideas?

Drupal hook before or after render() function

I have a problem with my drupal page. We use the opigno tool (its a module to that allows to create course - nodes which can be bought).
Now we have a problem with the view of the course-node. Everything works fine until a user bought the course and the drupal commerce status is on "pending". The problem now is that the node is showing nothing except the title of the course.
I began to think whats going on and took a look to the view settings for the course-view. Nothing (no Permission was set, no filter criteria ...)
Then I took a look at the template override of the course-view. And then I saw smth ...
print render($content['body']);
Ah! A render function to render the content of the view. So I asked myself: What is in content ?
After printing out the $content variable I saw this:
Array
(
[body] => Array
(
[#theme] => field
[#weight] => 1
[#title] => Description
[#access] =>
[#label_display] => hidden
[#view_mode] => full
[#language] => und
[#field_name] => body
[#field_type] => text_with_summary
[#field_translatable] => 0
[#entity_type] => node
[#bundle] => course
[#object] => stdClass Object
(
[vid] => 185
[uid] => 60
[title] => Demo Course
[log] =>
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[vuuid] => 16e7999b-28bb-4f3e-8bed-54a21b17f398
[nid] => 176
[type] => course
[language] => und
[created] => 1406897520
[changed] => 1407145285
[tnid] => 0
[translate] => 0
[uuid] => 22baf19a-dc32-4137-b698-89f1bb4adc59
[revision_timestamp] => 1407145285
[revision_uid] => 1
[body] => Array
(
[und] => Array
(
[0] => Array
(
[value] =>
This is a sample course for beta testers, it will show you the structure of the courses.
Here usually is displayed the description of the course.
Please "enroll" if you want to see the contents of this demo course.
[summary] => This is a sample course for beta testers to help you see the structure of a course. Please have a look on it!
[format] => html
[safe_value] =>
This is a sample course for beta testers, it will show you the structure of the courses.
Here usually is displayed the description of the course.
Please "enroll" if you want to see the contents of this demo course.
[safe_summary] => This is a sample course for beta testers to help you see the structure of a course. Please have a look on it!
)
)
)
)
Aaah! So $content has the content, but its not printed out with render()! But why ?
I searched in google for a hook which are able to "override" the render function and maybe deny the output when the user is on "pending". But... nothing.
I found this hook:
{hook}_node_view()
I searched for a using of this hook in all modules but when deleteing these functions from the modules did not changed anything. Are there other options to "override" the render() function ? Another hooks I can search for ? Or maybe you had the same problem with opigno ?
I am sorry - the problem was the Opigno Field Access Module. I deactivated it and it works like a charm.

How are Wordpress Dynamic Sidebar Widgets rendered?

I have been reading through the Wordpress Source, trying to get a better understanding of how dynamic sidebars are rendered.
However, I am hitting a sticking point...
894 | do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] );
I can't find where add_action('dynamic_sidebar', ... ) is defined. Without that part, I am sort of lost in what happens.
See the code here:
https://github.com/WordPress/WordPress/blob/b7c13e27c255e1fc1f03ab2ab432f1652a0ac212/wp-includes/widgets.php#L894
And to give more context, I am trying to figure out how to grab an array of widgets from a specific sidebar, and from there, I need to know how would you render each widget within that array.
I need finer control than dynamic_sidebar(...); gives me
Well, that specific line permits you to access each registered Widget properties, and it's used like:
<?php
/* Plugin Name: Test registered widgets */
add_action( 'dynamic_sidebar', 'sidebar_widgets_so_18666065' );
/**
* As this is an action hook, we don't return nothing
* use the passed values to do your stuff
*/
function sidebar_widgets_so_18666065( $registered_widget )
{
# Each registered widget passes the following array
/*
$registered_widget = Array
(
[name] => Meta
[id] => meta-2
[callback] => Array
(
[0] => WP_Widget_Meta Object
(
[id_base] => meta
[name] => Meta
[widget_options] => Array
(
[classname] => widget_meta
[description] => Log in/out, admin, feed and WordPress links
)
[control_options] => Array
(
[id_base] => meta
)
[number] => 2
[id] => meta-2
[updated] =>
[option_name] => widget_meta
)
[1] => display_callback
)
[params] => Array
(
[0] => Array
(
[number] => 2
)
)
[classname] => widget_meta
[description] => Log in/out, admin, feed and WordPress links
)
*/
}
Relevant search query at WordPress Answers.

Wordpress custom query comparing two timestamp meta data

I am trying to query posts by comparing meta value.
I have set two meta with the posts. i.e. 'start_date' and 'end_date'.
they are stored as UNIX timestamp.
Now I want to query posts on following conditions:
timestamp of current momment is after(greater than) 'start_date'.
timestamp of current momment is before(smaller than) 'end_date'.
In this case, I want both conditions to fulfill. So, I have used 'relation'=>'AND'.
So here is the print_r of the query:
Array
(
[post_type] => ads
[meta_query] => Array
(
[relation] => AND
[0] => Array
(
[kye] => start_date
[compare] => <=
[value] => 1352054503
[type] => NUMERIC
)
[1] => Array
(
[kye] => end_date
[compare] => >=
[value] => 1352054503
[type] => NUMERIC
)
)
)
Note: ads is a custom post type.
And here is meta of a post:
Array
(
[start_date] => Array
(
[0] => 1352160000
)
[end_date] => Array
(
[0] => 1352246400
)
)
I see absolutely no reason why this post should show up.
The start date timestamp(1352160000) is bigger than the current timestamp(1352054503). Which breaks condition #1.
So, why is this still showing up?
What do you think?
In your meta_query, you're using "kye" instead of "key".

Resources