i need to ad to wp all import the field "_ebay_ean" for every variations, i finded this functions:
<?php
/**
* ==================================
* Filter: wp_all_import_variation_taxonomies
* ==================================
*
* Can be used to add taxonomies to WooCommerce product variations.
*
*
* #param $taxonomies array - List of taxonomies.
*/
add_filter( 'wp_all_import_variation_taxonomies', 'wpai_wp_all_import_variation_taxonomies', 10, 1 );
function wpai_wp_all_import_variation_taxonomies( $taxonomies ){
if ( ! in_array( 'my_taxonomy_name', $taxonomies ) ) $taxonomies[] = 'my_taxonomy_name';
return $taxonomies;
}
is there a way to make this functions working to add for every variations imported to add the _ebay_ean field that must be one of value of my xml?
Related
Does anyone know how to remove the highlighted class from the woocommerce review section?
The comment-author-[USER-ID] or [USER-NICKNAME] class can be removed by using the WordPress comment_class filter hook.
So you get:
/**
* Filters the returned CSS classes for the current comment.
*
* #since 2.7.0
*
* #param string[] $classes An array of comment classes.
* #param string $class A comma-separated list of additional classes added to the list.
* #param int $comment_id The comment ID.
* #param WP_Comment $comment The comment object.
* #param int|WP_Post $post_id The post ID or WP_Post object.
*/
function filter_comment_class( $classes, $class, $comment_id, $comment, $post_id ) {
// Loop through classes
foreach ( $classes as $key => $class ) {
// Check if a string contains a specific word
if ( strpos( $class, 'comment-author') !== false ) {
// Unset a given variable
unset( $classes[$key] );
}
}
return $classes;
}
add_filter( 'comment_class', 'filter_comment_class', 10, 5 );
I'm trying to override the number of Items Per Page that a user sets in Screen Options for a specific post type (WP Admin only, not the front end). In this case and for a specific post type, I'd like it to list all posts (regardless of user-set limit) when you click on the post type in WP Admin (edit.php).
I've searched and tried several filter and action hooks but nothing has worked. I'm confident that it is possible.
WordPress 4.9.7
PHP 7.1.17
Multisite
Thank you,
Daniel
EDIT: I forgot to mention - I'm trying to do this from a plugin.
WordPress tries to derive this from the wp_usermeta table if it exists, otherwise it just defaults to 20. You can filter the metavalue and provide a different default - the key may change if on a multisite so you should check the usermeta table if need be.
/**
* Override pagination settings
*
* #param Integer $meta_value
* #param Integer $user_id
* #param String $meta_key
*
* #return Integer $meta_value
*/
function so51343268( $meta_value, $user_id, $meta_key ) {
/**
* The specific meta key is a combination of the post type and keywords.
* For 'post' it would be: `edit_post_per_page`
* For 'category' it would be: `edit_category_per_page`
*/
if( false !== strpos( $meta_key, '_per_page' ) ) {
/* Object Type Slug => Pagination Override */
$unpaginated_types = array(
'post' => 999,
'category' => 4,
);
/* Remove prefix and postfix to get the object type */
$type = rtrim( ltrim( $meta_key, 'edit_' ), '_per_page' );
if( isset( $unpaginated_types[ $type ] ) ) {
$meta_value = $unpaginated_types[ $type ];
}
}
return $meta_value;
}
add_filter( 'get_user_metadata', 'so51343268', 10, 3 );
Using the 'Local Pickup Plus' extension by Woothemes, I want to edit/filter the pickup locations. More specifically, I want to remove the province from each location.
I believe this is the filter I want to use:
/**
* Returns the array of shipping methods chosen during checkout
*
* #since 1.7.2
* #return array of chosen shipping method ids
*/
public static function get_chosen_shipping_methods() {
$chosen_shipping_methods = isset( WC()->session ) && WC()->session->get( 'chosen_shipping_methods' ) ? WC()->session->get( 'chosen_shipping_methods' ) : array();
/**
* Filters the chosen shipping methods
*
* #since 1.13.0
* #param array $chosen_shipping_methods array of chosen shipping method ids
*/
return apply_filters( 'wc_shipping_local_pickup_plus_chosen_shipping_methods', $chosen_shipping_methods );
}
This is my filter so far:
add_filter( 'wc_shipping_local_pickup_plus_chosen_shipping_methods', 'boltmobile_filter_pickup_locations' );
function boltmobile_filter_pickup_locations( $chosen_shipping_methods ) {
}
Before I can write the filter, I am getting error:
Warning: in_array() expects parameter 2 to be array, null given in /wp-content/plugins/woocommerce-shipping-local-pickup-plus/classes/class-wc-shipping-local-pickup-plus.php on line 891
Parameter two needed to be an array
add_filter( 'wc_shipping_local_pickup_plus_chosen_shipping_methods', $chosen_shipping_methods, 'boltmobile_filter_pickup_locations' );
function boltmobile_filter_pickup_locations() {
}
Is it possible to disable preloaded posts on a Archive-Page like archive-computers.php?
Example (archive-computers.php):
<?php
/**
* The archive template file
*
* #link http://codex.wordpress.org/Template_Hierarchy
* #package WordPress
* #subpackage mydomain.de
*/
var_dump($posts);
?>
Yes, here i have already posts in $posts. In my case the default posts_per_page => 10.
The problem is i dont need this because iam using here custom-queries on this page. So, how i can disable/prevent this "unused" query. Its waste performance.
Thats solves my issue!
function _cancel_query( $query ) {
if ( !is_admin() && is_post_type_archive( 'computer' ) ) {
$query = false;
}
return $query;
}
add_action( 'posts_request', '_cancel_query' );
I am trying to add custom validation message for any field, but its show only default error message.
Here's a snippet that should fix your issue. I just ran into this myself and didn't understand why it wasn't working. Just drop it into your theme functions.php file.
<?php
add_filter( 'gform_field_validation', 'mytheme_fix_custom_validation', 10, 4 );
/**
* Fixes Gravity Forms Custom validation message.
*
* #param array $result The result array.
* #param string $value The value of the field.
* #param array $form The Gravity Form array.
* #param object $field The form field object.
*
* #return array The result array.
*/
function mytheme_fix_custom_validation( $result, $value, $form, $field ) {
if ( ! $result['is_valid'] && ! empty( $field->errorMessage ) ) {
$result['message'] = $field->errorMessage;
}
return $result;
}
Here's a gist in case it ever changes:
https://gist.github.com/solepixel/c8ab2ff61ed55bffa52b5b2a21663c0f
It uses the filter documented here:
https://docs.gravityforms.com/gform_field_validation/