hide gravityform field labels from Woocommerce email notifications - woocommerce

I want to filter out unwanted order item meta data from Woocommerce email notifications especially gravity forms field labels. With gravityforms and gravity forms product add on it is possible that any customer can engrave a product. licence plates for cars etc.
e.g. eins:M zwei:TU drei:2019 .
I want to hide the field labels (eins, zwei, drei) and the double points in the email-notifications.
https://einsautoschilder.de/wp-content/uploads/2019/09/itemmeta.png
With dt.variation{display:none;} CSS rule I can hide the labels on cart and checkout page, but not in the emails.

To learn more about woocommerce order item meta data i found a very good tutorial
by Igor Benic.
"How to manage order item data in WooCommerce" | https://www.ibenic.com/manage-order-item-meta-woocommerce
With the following code it is possible
1) to hide gravityform field labels from woocommerce email notifications,
2) to change the order item meta title
add_filter( 'woocommerce_order_item_display_meta_key', 'change_order_item_meta_title', 20, 3 );
/**
* Changing a meta title
* #param string $key The meta key
* #param WC_Meta_Data $meta The meta object
* #param WC_Order_Item $item The order item object
* #return string The title
*/
function change_order_item_meta_title( $key, $meta, $item ) {
// By using $meta-key we are sure we have the correct one.
if ( 'eins' === $meta->key ) { $key = ''; }
return $key;
}
the code works in functions.php of your theme

Related

Exclude Backorder Products from WooCommerce Composite Options

I'm using WooCommerce Composite Products to create customer configurable packages from existing items in our Woo shop. These packages need to consist of In Stock products only, ignoring anything that is set to backorder.
For "Composite Options" I am using product categories (we have too many products to add individually), however doing it this way adds all products that are currently on backorder and set to "Allow, but notify customer".
Ideally I need a solution that allows me to use product categories which ignores any products that are set to backorder.
I tried to edit an existing snippet which would create a filter for backorder products but was not able to make any difference to the front end visible products, I'm sure more needs to be done to make it work. This is the original snippet I edited:
add_filter( 'woocommerce_composite_component_options_query_args_current', 'sw_cp_exclude_out_of_stock_options' );
function sw_cp_exclude_out_of_stock_options( $args ) {
$args[ 'exclude_out_of_stock' ] = true;
return $args;
}
I'm pretty sure the following is the basis of the code needed to figure out how to exclude back order products from component options (taken from Composite Products Plugin Editor):
woocommerce composite products > includes > data > class-wc-product-composite-data-store-cpt.php Line 1040 + 1041:
`// See 'WC_CP_Component::exclude_out_of_stock_options'.
'exclude_out_of_stock' => false`
woocommerce composite products > includes > class-wc-cp-component.php Line 785 - 789:
` /**
* Controls whether out of stock component options should be hidden.
*
* #since 8.0.3
*
* #return boolean
*/
public function exclude_out_of_stock_options() {
return apply_filters( 'woocommerce_component_options_exclude_out_of_stock', 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ), $this );
}`
Can anyone help me with the automated solution to this problem?

Advanced Custom Fields Default Values Based On Current User

How to set product field value based on current user's display name in ACF plugin?
Following acf/load_field[acf/load_field filter documentation][1] I tried adding this to my functions.php:
function acf_load_user_display_name( $field ){ $user = wp_get_current_user(); $display_name = $user->display_name; return $user->display_name; } // acf/load_field - default for product_display_name field add_filter('acf/load_field/name=product_display_name', 'acf_load_user_display_name');
This code makes a bug on the edit-product page and ACF-edit-field groups, and the custom field "product_display_name" is still blank on the product page.
[1]: https://www.advancedcustomfields.com/resources/acf-load_field/

How can I add a default billing title to WooCommerce?

I'm currently looking for a hook, to add a default billing title to the billing_title select to the WooCommerce checkout and change-address setting at the MyAccount page.
It should be something like Please select salutation and should be a required field. This field comes from the WooCommerce Germanized plugin and is a required field in Germany. Because of this there is no documentation about this (sadly).
This is my solution:
/**
* Add billing title default selection value
*/
add_filter( 'woocommerce_gzd_title_options', 'add_new_billing_title', 10, 1 );
function add_new_billing_title( $titles ) {
array_unshift( $titles, 'Bitte auswählen' );
return $titles;
}
I'm using array_unshift to add the default Please select value in German as first element in the select.

How to create a wordpress widget based on post settings

I would like to create a WordPress plugin/widget that I can add to my post either through the Visual Composer area (widget should be selectable) or simply as a shortcode.
The functionality of this widget is that it should allow me to take the settings of that post as an argument in the main function so that I can change the output of the widget based on what is selected for the post.
For example, I have categories for all my posts and if I have a certain category selected, I want to change the output of the widget based on that.
Does anyone know of a good boilerplate to get me started with this?
Thanks
You can create your own widget using the Widget API or the Shortcode API for shortcodes.
Since you want to change the content shown in your, for instance, widget, based on the current post, in the widget() method (which is the method that prints your widget's content in the frontend) you can add your conditionals or whatever you want to print there.
The $post is available in your widget, so you can use functions like get_post_meta() to retrieve the post's settings if you use custom fields, or any other function like get_the_ID() or has_category().
For example:
/**
* Outputs the content of the widget
*
* #param array $args
* #param array $instance
*/
public function widget( $args, $instance ) {
if ( has_category( 'books' ) ) {
echo 'Hey!, I have the Books category!';
} else {
echo "Hey... I don't.";
}
}

woocommerce plugin remove item

i am new to woocommerce, actually i want to customize product display so i manually parse products from database i want to remove an item from woocommerce cart through product id, i have found this function,
$woocommerce->cart->get_remove_url($cart_item_key); in core woocommerce cart class, but i am unable to understand what i have to write in $cart_item_key, i have tried to product id or product url in it but its not removing product item from cart, can somebody help me please what i have write in this variable $cart_item_key,
/* Gets the url to remove an item from the cart.
*
* #return string url to page
*/
its description of that function, i have tried using full url of product page and also slug
Regards
Arsalan
I know its an old post but it may help someone.
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
if($cart_item['product_id'] == $your_product_id)
$woocommerce->cart->get_remove_url($cart_item_key);
}
Hope its helps..

Resources