Change Verbiage on WooCommerce Subscriptions Customer Facing - wordpress

I'm looking to change the verbiage for the word "Suspend" to the word "Pause" on the customer-facing side of WooCommerce Subscriptions. I have the filter that pulls up the action buttons but I'm unsure of how to pull the specific action of "Suspend" and change it to the word "Pause".
Here is the filter.
apply_filters( 'wcs_view_subscription_actions', $actions, $subscription );
Any help would be much appreciated. If you need more information I'm happy to provide what I can.

You can use the wcs_view_subscription_actions filter hook. this way. check below code. code will go in your active theme functions.php file.
add_filter( 'wcs_view_subscription_actions', 'change_action_buttons_label', 10, 2 );
function change_action_buttons_label( $actions, $subscription ){
if( isset( $actions['suspend'] ) ){
$actions['suspend']['name'] = __( 'Pause', 'woocommerce-subscriptions' );
}
return $actions;
}

Related

Custom field value set to permalink only on new post, But they change it every time it's updated

I want to set the permalink slug using the custom field value for the first save only, but it is not working.
The code below changes the slug not only for the first save, but also for every update.
function custom_slug_auto_setting( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
return $_POST['custom_field_title'];
}
add_filter( 'wp_unique_post_slug', 'custom_slug_auto_setting', 10, 6 );
For the second and subsequent saves, I want to keep the slug set for the first save.
I tried using the filter hook for wp_insert_post to specify post_name only for the first save, but that didn't work well either.
Is there any good solution?
Thank you.
save_post or save_post_{$post->post_type} Fires once a post has been saved. The dynamic portion of the hook name, {$post->post_type}, refers to the post type slug.
We need to discard any updates autosave or revision actions. The WordPress autosave system fire every 60 seconds.
#See https://wordpress.org/support/article/revisions/
The $update parameter is supposed to determined whether this is an existing post being updated. It applies more specifically to a post autosave revision. The $update parameter will always be true when firing through wp_publish_post. But that isn't true for its usage in wp_insert_post (See the following wordpress stackexchange answer and comments for more details...).
#See https://wordpress.stackexchange.com/a/185991/190376
In our case, the wp_publish_post function publish a post by transitioning the post status.
#See https://developer.wordpress.org/reference/functions/wp_publish_post/
By additionally crosschecking the post status we can effectively determine whether it is indeed a non-existing post.
If you are calling a function such as wp_update_post that includes the save_post hook, your hooked function will create an infinite loop. To avoid this, unhook your function before calling the function you need, then re-hook it afterward.
#See https://developer.wordpress.org/reference/hooks/save_post/#avoiding-infinite-loops
save_post will fire on post Update (eg: Autosave) or Publish which is why we're runing into an infinite loop.
#See https://wordpress.stackexchange.com/a/19539/190376
<?php
add_action( 'save_post', 'wpso74121743', 10, 3 ); //can be replaced by save_post_{$post->post_type}
if ( ! function_exists( 'wpso74121743' ) ) {
function wpso74121743( $post_id, $post, $update ) {
if ( ! wp_is_post_autosave( $post_id ) && ! wp_is_post_revision( $post_id ) && ! $update && $post->post_status == 'auto-draft' ) {
$override_post_name = sanitize_title( get_post_custom_values( 'custom_field_title', $post_id ), get_the_title( $post_id ) );
add_action( 'save_post', 'wpso74121743', 10, 3 ); //can be replaced by save_post_{$post->post_type}
wp_update_post( array(
'ID' => $post_id,
'post_name' => $self,
) );
add_action( 'save_post', 'wpso74121743', 10, 3 ); //can be replaced by save_post_{$post->post_type}
};
};
};

WooCommerce - Making a checkout field required

on my baked goods site, I have WooCommerce installed and another plugin called Order Delivery Date for WooCommerce.
I installed the second plugin so my customers would be able to choose a delivery date for their items, however, I am trying to make the form field a required field. So far, I've just been able to make the field look like a required field, but have not figured out how to make sure that it is actually enforced. Any ideas?
Also, if anyone is familiar with WooCommerce, do you know how I would be able to make it so that customers receive this delivery date information in their order confirmation emails?
Thank you in advance!
My site: www.monpetitfour.com
You should try to had something like that :
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
// You can make your own control here
if ( ! $_POST[ 'e_deliverydate' ] )
wc_add_notice( __( 'Please select a delivery date' ), 'error' );
}
For the email, the easiest is to save the meta value ( I think it's already done by your plugin). Then you need to copy the template email (customer-processing-order.php) on your theme and change in the template :
<?php $delivery_date = get_post_meta( $order->id, 'custom_field_date', true);
// If the plugin is well developed, you can't directly use magic getters :
// $delivery_date = $order->e_deliverydate;
// Can only by use if the post meta start with _
?>
Your delivery date is <?php echo $delivery_date ?>
You can also use
date_i18n( woocommerce_date_format(), strtotime( $delivery_date ) );
In order to format the date correctly.
On the code above, you just need to find the name of the custom field used by the plugin ( you can search easily on the table wp_postmeta searching by an existing order (should be _e_deliverydate).
Add the following code to your theme's functions.php file
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
// Check if set, if its not set add an error.
if ( ! $_POST['e_deliverydate'] )
wc_add_notice( __( 'Please select a delivery date.' ), 'error' );
}
Now to get the email to show the custom field,
add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');
function my_woocommerce_email_order_meta_keys( $keys ) {
$keys['Delivery Date'] = '_e_deliverydate';
return $keys;
}
EDIT : Seems the field value isn't being saved to the database, try saving it explicitly
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['e_deliverydate'] ) ) {
update_post_meta( $order_id, '_e_deliverydate', sanitize_text_field( $_POST['e_deliverydate'] ) );
}
}

Woocommerce remove admin order item item meta

Im adding a custom item meta to every item with woocommerce_add_order_item_meta action.
I dont need to show this custom meta in the Order Detail, because it's an arry stringy that im using to print a pdf.
How can i remove this meta custom item? Is there some action to do it?
Thanks
I understand its a bit old question but I am answering for some other users who will have same issue in future.
If you want your order item meta to not display in admin order details page than you should append underscore (_) at the start of your meta name.
Example:
_custom_order_meta
The underscore trick no longer works. In Woo 3.x there is a hidden meta array:
add_filter('woocommerce_hidden_order_itemmeta',
array($this, 'hidden_order_itemmeta'), 50);
function hidden_order_itemmeta($args) {
$args[] = 'my_hidden_meta';
return $args;
}
It sounds like you need to keep it in order to print the PDF. If you override the order-details.php template you can possibly change:
$item_meta = new WC_Order_Item_Meta( $item['item_meta'], $_product );
to
$array = $item['item_meta'];
if( isset( $array['your_pdf_array_key'] ) ){ unset( $array['your_pdf_array_key'] ); }
$item_meta = new WC_Order_Item_Meta( $array, $_product );
EDIT
The wc_add_order_item_meta() function has 4 parameters as seen in the code:
function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) {
return add_metadata( 'order_item', $item_id, $meta_key, $meta_value, $unique );
}
If you choose a $meta_key with a preceding underscore, the meta will be automatically hidden from view on the checkout/order-received page, the My Order's list of the My account area, as well as in the admin's order overview page.
Therefore, I would suggest making your woocommerce_add_order_item_meta callback function look something like the following:
add_action( 'woocommerce_add_order_item_meta', '25979024_add_order_item_meta', 10, 3 );
function 25979024_add_order_item_meta( $order_item_id, $cart_item, $cart_item_key ) {
wc_add_order_item_meta( $order_item_id, '_pdf_something', 'hide this stuff' );
}

WooCommerce pass order data into woocommerce_checkout_update_user_meta

I'm trying to add user_meta upon checkout in WooCommerce. Currently I'm using woocommerce_checkout_update_user_meta action to update user meta. I'd like to pass some of the order data itself in as well specifically I'd like to make the order id the value of the meta like so...
function woocommerce_add_my_user_meta( $user_id ) {
global $woocommerce;
update_user_meta( $user_id, 'purchased', ''.$order->ID.'' );
}
add_action('woocommerce_checkout_update_user_meta', 'woocommerce_add_my_user_meta');
This however is not working. It's just adding a blank purchased user meta.
Any help greatly appreciated.
You could use the woocommerce_checkout_update_order_meta hook
// Use hook after checkout
add_action( 'woocommerce_checkout_update_order_meta', 'do-additional-stuff-on-checkout', 10, 2 );
// Things you want to be done when hook is called
function do-additional-stuff-on-checkout( $order_id, $post_values ) {
// get user
$current_user = wp_get_current_user();
// update
update_user_meta( $current_user->ID, 'purchased', $order_id );
}

WooCommerce Add Product Link in Processing Order Email

I want to add the product link in the Processing Order email which User receives when order. When an order is placed an Order Email sent, I want to get the product link there when user clicks redirects to the detail product page when clicked. Is there any way, I get the product link or the Product Title would Hyperlink.
THANKS
The answer from gunbunnysoulja works great but needs two little updates:
get_product needs to be wc_get_product
$_product->id needs to be $_product->get_id()
The updated answer is as follows:
add_filter( 'woocommerce_order_item_name', 'display_product_title_as_link', 10, 2 );
function display_product_title_as_link( $item_name, $item ) {
$_product = wc_get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
$link = get_permalink( $_product->get_id() );
return ''. $item_name .'';
}
I am currently using this solution, which I found in the comments on another page. This is not my code.
http://www.vanbodevelops.com/tutorials/add-a-link-back-to-the-order-in-woocommerce-new-order-notifications-email#comment-636
add_filter( 'woocommerce_order_item_name', 'display_product_title_as_link', 10, 2 );
function display_product_title_as_link( $item_name, $item ) {
$_product = get_product( $item['variation_id'] ? $item['variation_id'] : $item['product_id'] );
$link = get_permalink( $_product->id );
return ''. $item_name .'';
}
To link a product name with its product page in your order emails, open the functions.php file of your child theme and add the following snippet of code:
* Product Links in WooCommerce Order Emails
*/
add_filter('woocommerce_order_item_name', 'woocommerce_order_item_link', 10, 3);
function woocommerce_order_item_link( $item_name, $item, $bool ) {
$url = get_permalink( $item['product_id'] ) ;
return ''.$item_name .'';
}
I have been wondering how this works as well. There is little info available anywhere - at least not much with detailed step by step instructions.
The best solution I have came up with is to edit the customer-processing-order.php.
All I did was open it up in a text editor and added a few lines of text to:
"Your order has been received and is now being processed. Your order details are shown below for your reference. Please visit "http://www.youlinkurl".
The end user will have to copy and paste that link unfortunately but at least it works.

Resources