There are two currencies on the WordPress/WooCommerce website. One currency is GBP and the other one is custom currency such as "ABC". The default currency symbol position is LEFT. However, We need to use the custom currency symbol on the right side. I tried some custom functions, but they did not work. How can I fix it? I'm still trying to practice PHP :( Thank you.
add_filter( 'woocommerce_currency_pos', 'change_currency_position' );
function change_currency_position(){
if( isset( $_GET['currency'], 'ABC' == $_GET['currency'] )) {
return 'right';
}
}
Related
Thanks in advance for anyone who can help with this. As I have many virtual/ downloadable items in my Woocommerce shopping page, is there a way to disable, or make the quantity field disappear, entirely but only for those types of items? I have had several occurrences where customers bought multiple of something that was digital, and since that didnt make much sense because they could download it multiple times, I wound up manually refunding the extra. To avoid this extra work, can qty get turned off if the downloadable checkbox is ticked on the product page, or something like that? And it just keeps the default qty of 1 during checkout.
Give this a try
function hide_downloadable_quantity_field_cart( $product_quantity, $cart_item_key, $cart_item ) {
if ( isset( $cart_item['data'] ) && $cart_item['data']->is_downloadable() ) {
$product_quantity = '';
}
return $product_quantity;
}
add_filter( 'woocommerce_cart_item_quantity', 'hide_downloadable_quantity_field_cart', 10, 3 );
It should remove the quantity field completely for downloadable items in the cart.
I am unable to get the acf text field to display in the woocommerce "Product Tag" admin dashboard.
I have tried the following code, along with many other different variations of looping through the products, retrieving their tags and returning the acf text field but no values are appearing in the columns.
The goal is to customize the Product Tag Admin Dashboard to display the acf text field term. I was able to achieve getting these text field terms in a different portion of code when I created a customize side bar that sections tags by categories that are different from the product categories. I tried that same code for the columns but that isn't working either.
add_filter( 'manage_edit-product_tag_columns', 'tag_category_column_admin', 9999 );
function tag_category_column_admin( $columns ){
$columns['tag_category'] = 'Tag Category';
return $columns;
}
add_action('manage_product_tag_custom_column', 'tag_category_column_admin_content', 10, 2);
function tag_category_column_admin_content($column,$product_id){
$product_tag_terms = wp_get_post_terms($product_id, 'product_tag');
foreach($product_tag_terms as $term){
$category_id = get_field('tag_category' , $term, true);
return $category_id;
}
if($column == 'tag_category'){
echo $category_id;
}
}
I have looked everywhere and cannot seem to find a solution to my problem. Please help!
really hoping someone can help with this as I thought it would be far more simple!
Long story short, I have created a script that populates the upsells of WooCommerce products, all works great using the API and they are there. They show on the product page as expected but in a completely different order to how they were inputted in the admin area and I cannot seem to find a way for the order to follow admin?
function filter_woocommerce_upsells_orderby( $orderby ) {
return 'menu_order';
};
add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );
Above is the hook I have found but from the options I have found such as menu order / id / price etc, there is not simply an overide option to ignore the order and just take them as they are in admin!?
Please help!
I also encountered this problem. And i have an idea.
I checked all wordpress parameters about Order & Orderby.Link is https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters.
And i use the paramteters name "none",It can make your orderby not based on any sorting rules.In other words, it is sorted according to upsells. here is the code.
// ORDER BY
add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );
function filter_woocommerce_upsells_orderby( $orderby ){
return "none";
};
// ORDER
add_filter( 'woocommerce_upsells_order', 'filter_woocommerce_upsells_order', 10, 1 );
function filter_woocommerce_upsells_order(){
return 'asc'; // Default is 'desc';
};
But it is still chaotic, when adding any product to upsells, it is still random. Therefore I also used a plug-in "WooCommerce Drop/Drag For Upsells Cross-Sells", which allows you to drag your products in upsell at will.
If you have any question you can ask me.
Thanks.
been struggling finding a solution to my problem for weeks.
Case :
I have a custom post type named : design. This CPT have a custom field (made with ACF plugin) called thematique. I created the same custom field (thematique) for design's categories.
Expected behaviour:
I want that whenever if we make a get_posts() or WP_Query if a design's thematique field is empty, it should inherit its categorie's thematique.
I've investigated into the pre_get_posts hook but I'm not quite sure how to handle it.
Anybody has an idea ?
Thanks in advance, I really appreciate your help !
You can just do this the easy way and inside your WP Query where you have the formatting for each returned item add this:
<?php $thematique = get_field('thematique'); //Gets current posts value of fiels
<?php if (empty($thematique)){ //Checks if the field is empty, if so do the following
$postCat = get_the_category(); //Get current posts category ID
$catID = 'category_' . $postCat; //Merge category ID and needed string for ACF
$thematique = get_field('thematique', $catID); //Updated the value of $thematique with categories value
}?>
Although not tested this should indeed work as it's how ACF says to get the value from categories. Find out more here.
#Ali_k
I'm not so sure about how to go about it though. I would need something like :
// Designs Thematique priority mechanic
function design_thematique_priority($query){
if($query->query['post_type'] == "design"){
foreach($query->posts as $post){
if($post->thematique == ""){
$post->thematique = $post->category->thematique;
}
}
}
}
add_filter( 'pre_get_posts', 'design_thematique_priority' );
But I don't think there is any loop I can use to loop through posts in pre_get_posts right ?
Basically, I finished building custom plugin for my client.
the only thing after products added to cart, before the checkout.
user able to change the quantity of the products, is it possible to display the selected quantity, but disabled the options to read only so client will able to see the quantity in cart page that he selected but can't change it?
and to apply this only to products that I used with my plugin either product ids or better category id because all the products there.
other product display and able to change quantity regular
by the way its regular products not virtual and not Sold Individually i need to find a way to limit clients to change quantity for some products only in cart page!, and not in product page.
I really appreciate any help.
As mentioned in the comment, you can use the woocommerce_cart_item_quantity filter for that. So that might look something like this:
function 668763_change_quantity_input( $product_quantity, $cart_item_key, $cart_item ) {
$product_id = $cart_item['product_id'];
// whatever logic you want to determine whether or not to alter the input
if ( $your_condition ) {
return '<h3>' . $item['quantity'] . '</h3>';
}
return $product_quantity;
}
add_filter( 'woocommerce_cart_item_quantity', '668763_change_quantity_input', 10, 3);
This would be just a simple example to replace the input with a h3 element containing the quantity. It can easily be adjust to alter the quantity input element to your liking.