i want to add custom text in checkout and cart page.
what code do I need to write to the function.php file?
beside to the "total" word. Always static.
Thank you
https://i.hizliresim.com/nJ4dBR.jpg
image1
Overriding the woocommerce checkout/review-order.php template.
You need first (if not done) to copy the templates sub folder located in in woocommerce plugin folder to your active child theme (or theme) folde, and rename it woocommerce.
Once done in your active theme go to woocommerce > checkout, and open/edit review-order.php template file.
At the end of this template you have this:
<?php do_action( 'woocommerce_review_order_before_order_total' ); ?>
<tr class="order-total">
<th><?php _e( 'Total', 'woocommerce' ); ?></th>
<td><?php wc_cart_totals_order_total_html(); ?></td>
</tr>
<?php do_action( 'woocommerce_review_order_after_order_total' ); ?>
</tfoot>
So you will change:
To:
Now you can save, you are done…
Hope this will helps you.
For more information,
Customize the text “Total” in WooCommerce checkout page
You will need to copy cart/cart-totals.php and checkout/review-order.php template files from woocommerce/templates to your theme's folder at <your-theme's-folder>/woocommerce/.
Then modify following templates.
Template Path: <your-theme's-folder>/woocommerce/cart/cart-totals.php
<tr class="order-total">
<th><?php _e( 'Total', 'woocommerce' ); ?></th>
<td data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>"><?php wc_cart_totals_order_total_html(); ?></td>
</tr>
Template Path: <your-theme's-folder>/woocommerce/checkout/review-order.php
<tr class="order-total">
<th><?php _e( 'Total', 'woocommerce' ); ?></th>
<td><?php wc_cart_totals_order_total_html(); ?></td>
</tr>
Modification Example
Edit <th><?php _e( 'Total', 'woocommerce' ); ?></th> with, for example,
<th><?php _e( 'Total', 'woocommerce' ); ?> <span> <?php _e('some text here', 'mm-woocommerce'); ?> </span></th>
We added <span> <?php _e('some text here', 'mm-woocommerce'); ?> </span>
Related
I'm very new to Wordpress/WooCommerce and I'm trying to do something I thought would have been simple.
The very basic WooCommerce Single Product page has the Product Attributes, they all appear under one big column.
Where can I actually modify the style and css for Product Page, so that I can have them in 2 columns?
I see the table is itself is generated under class "woocommerce-product-attributes" and "shop_attributes" ?
Any guidance is very appreciated.
Had the same issue, solved it by editing woocommerce/templates/single-product/product-attributes.php. To make the change permanent between woocommerce updates, copy the file contents to yourtheme/woocommerce/single-product/product-attributes.php.
Change:
<table class="woocommerce-product-attributes shop_attributes">
<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
</tr>
<?php endforeach; ?>
</table>
to:
<table>
<?php foreach (array_chunk($product_attributes, 2) as $product_attribute_key => $product_attribute) :{ ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<?php foreach ($product_attribute as $value) :{ ?>
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $value['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $value['value'] ); ?></td>
<?php } endforeach; ?>
</tr>
<?php } endforeach; ?>
</table>
i want to add a new column called image to myaccount-> orders -> view order
in the orders details table which displays the product image for the corresponding product item in the table like this
expected result
what i have tried
function display_remove_order_item_button( $item_id, $item, $order ){
// Avoiding displaying buttons on email notification
if( ! ( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) ) )
return;
$order_id = 569;
$order = wc_get_order( $order_id );
$product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
echo $product->get_image();
}
add_action( 'woocommerce_order_details_before_order_table', 'nolo_custom_field_display_cust_order_meta', 10, 1 );
but the image appears inside the product column
how can i achive the function in the picture ?
For that you will need to edit following templates:
templates/order/order-details.php & templates/order/order-details-item.php
First copy both templates in your active theme folder and add this lines
<th class="woocommerce-table__product-image product-image"><?php _e( 'Image', 'woocommerce' ); ?></th>
in order-details.php and
<td class="woocommerce-table__product-image product-image"><?php echo $product->get_image('thumbnail'); ?></td>
in order-details-item.php. If you need a reference of function get_image check this : https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html
order-details.php
<thead>
<tr>
<th class="woocommerce-table__product-name product-name"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th class="woocommerce-table__product-image product-image"><?php _e( 'Image', 'woocommerce' ); ?></th>
<th class="woocommerce-table__product-table product-total"><?php _e( 'Total', 'woocommerce' ); ?></th>
</tr>
</thead>
order-details-item.php
<td class="woocommerce-table__product-name product-name"></td>
<td class="woocommerce-table__product-image product-image"><?php echo $product->get_image('thumbnail'); ?></td>
<td class="woocommerce-table__product-total product-total">
<?php echo $order->get_formatted_line_subtotal($item); ?>
</td>
Currently there is no such a hooks / filters to achieved your modifications as per your images. But it can be possible by overridden woocommerce follows templates -
Override "order-details.php" template by copying it to yourtheme/woocommerce/order/order-details.php to add your "Image" header.
Override "order-details-item.php" template by copying it to yourtheme/woocommerce/order/order-details-item.php to add your "Image" to display.
I was wondering if it is possible to make fields in the admin area (for instance on the user page) required or optional.
Here I have take reference URL https://www.cssigniter.com/how-to-add-a-custom-user-field-in-wordpress/
Showing the user field
As mentioned in the registration form, actions ‘show_user_profile‘ and ‘edit_user_profile‘ are available for adding our own user fields. The former fires when users are seeing/editing their own profile information, while the latter fires when a user (such as an admin) sees/edits another user’s profile. Both actions pass a WP_User object as their sole parameter. Our previous code, which already uses those actions, was this:
add_action( 'show_user_profile', 'crf_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'crf_show_extra_profile_fields' );
function crf_show_extra_profile_fields( $user ) { ?>
<h3><?php esc_html_e( 'Personal Information', 'crf' ); ?></h3>
<table class="form-table">
<tr>
<th><label for="year_of_birth"><?php esc_html_e( 'Year of birth', 'crf' ); ?></label></th>
<td><?php echo esc_html( get_the_author_meta( 'year_of_birth', $user->ID ) ); ?></td>
</tr>
</table>
<?php
}
Let’s go ahead and change the plain text year of birth, to an input element, so that it may accept user input.
add_action( 'show_user_profile', 'crf_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'crf_show_extra_profile_fields' );
function crf_show_extra_profile_fields( $user ) {
$year = get_the_author_meta( 'year_of_birth', $user->ID );
?>
<h3><?php esc_html_e( 'Personal Information', 'crf' ); ?></h3>
<table class="form-table">
<tr>
<th><label for="year_of_birth"><?php esc_html_e( 'Year of birth', 'crf' ); ?></label></th>
<td>
<input type="number"
min="1900"
max="2017"
step="1"
id="year_of_birth"
name="year_of_birth"
value="<?php echo esc_attr( $year ); ?>"
class="regular-text"
/>
</td>
</tr>
</table>
<?php
}
Let’s check our profile page:
I have created a child theme for twenty-seventeen in wordpress and created a slider function to display slider images and also a custom post type for the function.
Now I created an extra menu under appearances in dashboard as Slider settings and I need to manage the slider using that settings.
In that settings I need to have the following
o Enable slider option (check box)
o Enable slider only for logged in users (check box)
o Set a global title for slider block (text field)
I Added in back end but no condition added in front end to display slides based on this.
How could I do this?
You can use this code and change page for rendering options:
<?php
add_action('admin_menu', 'create_menu');
function create_menu() {
add_options_page(__( 'Plugin Settings', 'textdomain' ),__( 'Plugin Settings', 'textdomain' ), 'administrator', __FILE__, 'settings_page', __FILE__);
add_action( 'admin_init', 'mysettings' );
}
function mysettings() {
register_setting( 'settings-group', 'enable_slider' );
register_setting( 'settings-group', 'enable_slider_loggedin' );
register_setting( 'settings-group', 'slider_title' );
}
function settings_page() {
?>
<div class="wrap">
<h2><?php _e('PluginSettings','textdomain'); ?></h2>
<form method="post" action="options.php">
<?php settings_fields( 'settings-group' ); ?>
<?php do_settings_sections( 'settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e(' Enable slider','textdomain'); ?></th>
<td>
<input name="enable_slider" type="checkbox" value="1" <?php checked( '1', get_option( 'enable_slider' ) ); ?> />
<p class="description"></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Enable slider only for logged in users','textdomain'); ?></th>
<td>
<input name="enable_slider_loggedin" type="checkbox" value="1" <?php checked( '1', get_option( 'enable_slider_loggedin' ) ); ?> />
<p class="description"></p>
</td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Title For Slider','textdomain'); ?></th>
<td><input type="text" name="slider_title" value="<?php echo get_option('slider_title'); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
Using like this:
if ( get_option ('enable_slider') == 1 ) {
// enable
} else {
//disable
}
I want to show WordPress administration menus in custom dashboard widgets. How to do it?
Or just paste this tested solution in theme functions.php and modify. Then wherever you need you may call your admin setting by get_option()
corrected with input from b__ and tested again
function register_mysettings() {
register_setting( 'michal-option-group', 'new_option_name' );
register_setting( 'michal-option-group', 'some_other_option' );
}
add_action( 'admin_init', 'register_mysettings' );
function add_michal_dashboard_widget(){
wp_add_dashboard_widget(
'michal_dashboard_widget', // slug.
'Michal Dashboard Widget', // title
'michal_dashboard_widget_function' // widget code
);
}
function michal_dashboard_widget_function(){
if (isset($_POST['new_option_name'])) update_option( 'new_option_name', sanitize_text_field( $_POST['new_option_name']));
if (isset($_POST['some_other_option'])) update_option( 'some_other_option', sanitize_text_field( $_POST['some_other_option']));
?>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<?php settings_fields( 'michal-option-group' ); ?>
<?php do_settings_sections( 'michal-option-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">New Option Name</th>
<td><input type="text" name="new_option_name" value="<?php echo get_option('new_option_name'); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Some Other Option</th>
<td><input type="text" name="some_other_option" value="<?php echo get_option('some_other_option'); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
<?php
}
add_action( 'wp_dashboard_setup', 'add_michal_dashboard_widget' );
First of all: you should create a dashboard widget. you can read more about how to do it here:
Dashboard Widgets API
Now for showing the menu you should take a look at this post:
Get all available admin pages in Wordpress
Good luck!