Can't change 'cart' to be 'basket' in woocommerce - wordpress

I've tried adding this code:
add_filter( 'woocommerce_product_single_add_to_cart_text',
'woo_custom_cart_button_text' );
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text() {
return __( 'Add to basket', 'woocommerce' );
}
To functions PHP, but as you can still see by this page, only some of the text has changed to 'basket'
Page with 'cart'
However, on the other page it seems to have worked:
Working page
Why won't it change on the other page (the text), but on the single product page?

Add another line to your code -
add_filter( 'woocommerce_product_add_to_cart_text', 'woo_custom_cart_button_text',999 );

add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
add_filter( 'woocommerce_product_single_add_to_cart_text', 'custom_woocommerce_product_add_to_cart_text' );
function custom_woocommerce_product_add_to_cart_text() {
return __( 'Read more', 'woocommerce' );
}
Try this filter

Related

Wordpress shortcode not rendering in Yoast og:title

I have a simple shortcode which i use on post titles:
add_shortcode('year', 'year_shortcode');
function year_shortcode() {
$year = date('Y');
return $year;
}
add_filter( 'single_post_title', 'my_shortcode_title' );
add_filter( 'the_title', 'my_shortcode_title' );
add_filter('wpseo_title', 'my_shortcode_title');
add_filter( 'wpseo_metadesc', 'my_shortcode_title' );
function my_shortcode_title( $title ){
return do_shortcode( $title );
}
It works fine but I suddenly realized that Yoast creates an og:title and it doesn't render there (meaning it doesn't render on Facebook or whatsapp)
I searched for an answer and couldn't find anythinng.
Has anyone faced this before?
Maybe I need to run the og:title through a filter of some sort which is also fine, the question is how.
Thanks in advance.
I used this and it mostly works.
It will update the og:title, and socials etc in Yoast.
It does not update Yoast's default Schema output. This would probably need to be addressed by them.
// Create Year shortcode to replace with current year.
add_shortcode( 'currentyear', 'current_year' );
function current_year() {
$year = date( 'Y' );
return $year;
}
// Activate shortcode function in Post Title.
add_filter( 'the_title', 'do_shortcode' );
add_filter( 'single_post_title', 'do_shortcode' );
add_filter( 'wpseo_title', 'do_shortcode' );
add_filter( 'wpseo_metadesc', 'do_shortcode' );
add_filter( 'wpseo_opengraph_title', 'do_shortcode' );
add_filter( 'wpseo_opengraph_desc', 'do_shortcode' );
add_filter( 'wpseo_opengraph_site_name', 'do_shortcode' );
add_filter( 'wpseo_twitter_title', 'do_shortcode' );
add_filter( 'wpseo_twitter_description', 'do_shortcode' );
add_filter( 'the_excerpt', 'do_shortcode' );

Need to Change Sale Badge Text in WooCommerce

The following works for the Product page but it does not work for the Shop page.
<?php
add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{
return '<span class="onsale">PUT YOUR TEXT</span>';
}
Please suggest modifications.
Thanks!
Use This
add_filter( 'woocommerce_sale_flash', 'wooc_custom_replace_sale_text' );
function wooc_custom_replace_sale_text( $html ) {
return str_replace( __( 'Sale!', 'woocommerce' ), __( 'Your Text', 'woocommerce' ), $html );
}
I tried your code and it works perfectly for the shop page as well. You may try increasing the priority or it can be a conflict with some other plugin or theme.
You may also check the following file to confirm it has applied the woocommerce_sale_flash filter
woocommerce\templates\loop\sale-flash.php

Remove login form toggle in woocommerc checkout page

I'm trying to make the login form in checkout page visible without the toggle
here is what form-login.php looks like
<div class="woocommerce-form-login-toggle">
<?php wc_print_notice( apply_filters( 'woocommerce_checkout_login_message', esc_html__( 'Returning customer?', 'woocommerce' ) ) . ' ' . esc_html__( 'Click here to login', 'woocommerce' ) . '', 'notice' ); ?>
</div>
I need to remove that toggle and make the login form always visible
Thank you
I found the answer here
Unhide Checkout Login form for unlogged users in Woocommerce
users-in-woocommerce
// Enable the login form by default for unlogged users
add_action( 'woocommerce_before_checkout_form', 'force_checkout_login_for_unlogged_customers', 4 );
function force_checkout_login_for_unlogged_customers() {
if( ! is_user_logged_in() ) {
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
add_action( 'woocommerce_before_checkout_form', 'custom_checkout_login_form', 20 );
}
}
function custom_checkout_login_form() {
wc_get_template( 'global/form-login.php', array(
'message' => __( 'If you have shopped with us before, please enter your details below. If you are a new customer, please proceed to the Billing & Shipping section.', 'woocommerce' ),
'redirect' => wc_get_page_permalink( 'checkout' ),
'hidden' => false,
) );
}

How do I change the add to cart text on the cart page only?

I'm trying to change the "add to cart" button text to 'Complete Sale' when on the shopping cart page, be "subscribe now" on product id 4968, and be 'Book' everywhere else.
Here is my code in the functions.php file:
function woo_custom_cart_button_text() {
if (is_single('Product1')) {
return __( 'Subscribe Now', 'woocommerce' );
} else {
return __( 'Book', 'woocommerce' );
}
}
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
Try to change is_single to is_page(). And put slug or id of the page inside the is_page().

wordpress moving publish metabox

I'm working on a plugin and I'm trying to:
1- move the publish metabox from side to the bottom of the page in the normal section.
2- force 1 column layout for the plugin custom post type edit page.
3- remove the screen options tab for the custom post type.
I'm using the next code block but it dont work:
function sds_do_meta_boxes() {
remove_meta_box( 'submitdiv', 'sliding_panel', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sliding_panel', 'normal', 'core' );
}
add_action('do_meta_boxes', 'sds_do_meta_boxes');
function SDS_init() { //The current user is already authenticated by this time
add_filter( 'screen_layout_columns', 'so_screen_layout_columns' );
add_filter( 'get_user_option_screen_layout_dashboard', 'so_screen_layout_dashboard' );
add_filter( 'screen_options_show_screen', 'SDS_remove_screen_options_tab');
}
add_action( 'init', 'SDS_init' );
function so_screen_layout_columns( $columns ) {
$columns['dashboard'] = 1;
return $columns;
}
function so_screen_layout_dashboard() {
return 1;
}
function SDS_remove_screen_options_tab() {
return false;
}
So, the 'publish' metabox is removed but it is not re-added. Also, the 1 column layout filters don't work. I need help:)
Changing the $priority parameter from core to high and setting priority of add_action to 0 should do the trick. I would also suggest using the dynamic add_meta_boxes_{$post_type} hook:
add_action( 'add_meta_boxes_sliding_panel', 'sds_do_meta_boxes', 0, 1 );
function sds_do_meta_boxes( $post )
{
remove_meta_box( 'submitdiv', 'sliding_panel', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sliding_panel', 'normal', 'high', null );
}

Resources