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() {
}
Related
I have a custom order status called 'quote', and I have added the following code to try and prevent stock levels being decremented for orders with this status.
function bw_do_not_reduce_quote_stock( $reduce_stock, $order ) {
if ( $order->has_status( 'quote' ) ) {
$reduce_stock = false;
}
return $reduce_stock;
}
add_filter( 'woocommerce_can_reduce_order_stock', 'bw_do_not_reduce_quote_stock', 10, 2 );
This works for orders placed on the front-end website. But if the admin adds or edits an order on the backend, the stock is decremented.
Is there an alternative hook for the backend? Or am I missing something else?
In addition to your current code, add the woocommerce_prevent_adjust_line_item_product_stock filter hook
/**
* Prevent adjust line item
*
* #param $prevent
* #param $item
* #param $quantity
*/
function filter_woocommerce_prevent_adjust_line_item_product_stock ( $prevent, $item, $quantity ) {
// Get order
$order = $item->get_order();
if ( $order->has_status( 'quote' ) ) {
$prevent = true;
}
return $prevent;
}
add_filter( 'woocommerce_prevent_adjust_line_item_product_stock', 'filter_woocommerce_prevent_adjust_line_item_product_stock', 10, 3 );
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 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?
Having code below (given in a class)
class X
{
public function __construct()
{
add_action( 'post_updated', array( $this, 'datachangecheck' ), 10, 3 );
}
function datachangecheck( $post_id, $post_after, $post_before )
{
if ( $post_before->post_title != $post_after->post_title )
{
//do whatever
}
return;
}
}
Above works fine when checking if a title has been changed, but is there any away way of managing the same thing when having metadata related to it?
I only want to know if any data has changed (I don't need any returned values). I can't manage to find any hook where I can see like meta_post_before and meta_post_after or similar. Can someone point me into right direction? Thank you!
This was kind of tricky, so I guess someone else might have the same issue so I share some code here and hopefully someone has any help from it :-) I have the most important part in the code below:
public function __construct()
{
add_action( 'post_updated', array( $this, 'datachangecheck' ), 10, 3 );
}
/*
* datachangecheck
*
* This function is called upon hook post_updated.
* The function checks if data for updated post has been changed,
* and saves a file when data has been changed
*
* #param string $post_id id of post affected
* #param WP_Post $post_after WP_Post after post has been updated
* #param WP_Post $post_before WP_Post before post has been updated
* #return N/A
*
*/
function datachangecheck( $post_id, $post_after, $post_before )
{
//Cast postobjects into arrays, so comparision is possible with builtin-php functions
$spf = (array)$post_before;
$spa = (array)$post_after;
//These would differ every update. so remove them for possible comparision
unset ( $spf['post_modified']);
unset ( $spf['post_modified_gmt']);
unset ( $spa['post_modified']);
unset ( $spa['post_modified_gmt']);
//Check if any difference between arrays (if empty no difference)
//If not empty, save file that tells plugin that data has been changed
$ard = array_diff ( $spf, $spa);
if ( !empty ( $ard ) )
{
$this->datahaschanged_save();
}
else
{
//No change of post native data, check if any metapost data has been changed
//Remove edit_last and edit_lock because they could differ without data being changed
$this->metadata_before = get_post_meta( $post_id );
unset ( $this->metadata_before['_edit_last']);
unset ( $this->metadata_before['_edit_lock']);
add_action('updated_post_meta', array( $this, 'checkmetadata_after'), 10, 2);
}
return;
}
/*
* checkmetadata_after
*
* This function is called upon hook updated_post_meta when data has been update, but no change in native post data
* has been made and saves a file when data has been changed
*
* #param string $post_id id of post affected
* #param WP_Post $post_after WP_Post after post has been updated
* #param WP_Post $post_before WP_Post before post has been updated
* #return N/A
*
*/
function checkmetadata_after( $meta_id, $post_id )
{
//Because updated_post_meta is used, now we can grab the actual updated values
//Remove edit_last and edit_lock because they could differ without data being changed
$this->metadata_after = get_post_meta( $post_id );
unset ( $this->metadata_after['_edit_last']);
unset ( $this->metadata_after['_edit_lock']);
//Make one-level index arrays of metadata
//so array_diff works correctly down below
$arr_mdb = $this->onelevel_array( $this->metadata_before );
$arr_mda = $this->onelevel_array( $this->metadata_after );
//Compare array with metapost values before and after
//If not empty, save file that tells plugin that data has been changed
$ard_metadata = array_diff ( $arr_mdb, $arr_mda );
if (!empty ( $ard_metadata))
{
$this->datahaschanged_save();
}
return;
}
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/