Is this possible to add Woocommerce Product Default Description for All Products page. That should be image or Note text. And I want It will be put in above or bottom of the description text.
Thanks in advance
you can use hooks like
// define the woocommerce_single_product_summary callback function
function my_custom_action() {
echo '<p>This is my custom action function</p>';
};
add_action( 'woocommerce_single_product_summary', 'my_custom_action', 15 );
or
woocommerce_after_single_product_summary
// define the woocommerce_after_single_product_summary callback
function action_woocommerce_after_single_product_summary( $evolve_woocommerce_after_single_product_summary, $int ) {
// make action magic happen here...
};
// add the action
add_action( 'woocommerce_after_single_product_summary', 'action_woocommerce_after_single_product_summary', 10, 2 );
or woocommerce_before_single_product_summary
// define the woocommerce_before_single_product_summary callback
function action_woocommerce_before_single_product_summary( $woocommerce_show_product_sale_flash, $int ) {
// make action magic happen here...
};
// add the action
add_action( 'woocommerce_before_single_product_summary', 'action_woocommerce_before_single_product_summary', 10, 2 );
or you may also change direct on woo-commerce files.
Related
I am trying to add a shortcode to all my woocommerce single product pages. I want the shortcode to appear above the short description.
I have found this code and added it to functions.php, but I can see that it adds the shortcode below the short description (and above the add to cart button).
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
$text = do_shortcode('[my-shortcode]');
return $description.$text;
}
I would be very gratefull for some help :)
function customShortcodeBeforeShortDescription( $post_excerpt )
{
echo do_shortcode('[wpqr-code]');
}
add_filter('woocommerce_short_description','customShortcodeBeforeShortDescription', 10, 1);
You can use the woocommerce_single_product_summary action hook. try the below code. The code will go in your active theme functions.php file.
function add_shortcode_before_short_description(){
echo do_shortcode( '[wpqr-code]' );
}
add_action( 'woocommerce_single_product_summary', 'add_shortcode_before_short_description', 15, 1 );
Tested and works
I don't want the customers to get linked to the myaccount-dashboard with the annoying Hello xy, from here you can blabla, when they click on "My Account".
Is there an endpoint for the my account dashboard? I didn't find it on the backend in woocommerce>Settings>Accounts...
What's working is: I set up a custom link under menu/navigation... called it "My Account" and set the link to /myaccount/downloads for example.
So, when customers are logged in and they click on My Account, they get redirected to Downloads.
I'm wondering, is there another way to get rid of the dashboard?
Or a redirect solution? Thanks.
Remove it using below function. change downloads to your requirement.
function custom_my_account_menu_items( $items ) {
unset($items['downloads']);
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items' );
Looking more closely it seems like there are a handful of ways to do this. Take a look at the my-account.php template. You could override this, but I found that if you remove the woocommerce_account_content hook, you get a deprecation notice and WooCommerce thinks you have an outdated template and adds the content anyway.
Looking at the template you will see two hooks. The side menu navigation is added to the woocommerce_account_navigation and the content is added to woocommerce_account_content function. You can remove the defaults from their hooks and add back just the downloads content.
function so_41983566_remove_account_dadshboard(){
remove_action( 'woocommerce_account_navigation', 'woocommerce_account_navigation' );
remove_action( 'woocommerce_account_content', 'woocommerce_account_content' );
add_action( 'woocommerce_account_content', 'so_41983566_download_content' );
}
add_action( 'woocommerce_account_navigation', 'so_41983566_remove_account_dadshboard', 1 );
function so_41983566_download_content(){
do_action( 'woocommerce_account_downloads_endpoint' );
}
Or woocommerce_account_content() and woocommerce_account_navigation() are both pluggable functions and you can just define new versions in your theme/plugin.
This link explains everything:
https://github.com/woocommerce/woocommerce/wiki/Customising-account-page-tabs
First you need to create an endpoint:
function my_custom_endpoints() {
add_rewrite_endpoint( 'my-custom-endpoint', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
function my_custom_query_vars( $vars ) {
$vars[] = 'my-custom-endpoint';
return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars', 0 );
Then create the menu item:
function my_custom_my_account_menu_items( $items ) {
$logout = $items['customer-logout'];
unset( $items['customer-logout'] );
$items['my-custom-endpoint'] = __( 'My Custom Endpoint', 'woocommerce' );
$items['customer-logout'] = $logout;
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'my_custom_my_account_menu_items' );
Add content to the endpoint
function my_custom_endpoint_content() {
echo '<p>Hello World!</p>';
}
add_action( 'woocommerce_account_my-custom-endpoint_endpoint', 'my_custom_endpoint_content' );
When the user gets to the checkout, there is a button , the "Place order" button at the bottom of the form. I have been trying to add a hook to this button in woocommerce, but I don't seem to find the correct one, I have tried woocommerce_checkout_place_order... but it doesnt do anything.
function my_function() {
//write function
}
add_action( "woocommerce_order_status_pending", "my_function");
Thanks in advance!
You need this hook woocommerce_review_order_after_submit. It will execute any function you hook to it just after the submit area. with this hook you can add some html on the checkout page after the submit button.
But if you need to call a function after the user have pressed the "Place order" button - use woocommerce_checkout_order_processed. This one will hook you just after the order was created so you can use the freshly generated order details:
add_action( 'woocommerce_checkout_order_processed', 'is_express_delivery', 1, 1 );
function is_express_delivery( $order_id ){
$order = new WC_Order( $order_id );
//something else
}
You may check this site for some more hooks you might use on the checkout page.
## I USED THIS CODE FOR ADDING DELIVERY CHARGES DEPENDING UPON THE CART SUBTOTAL AND SOME POST FIELDS ##
function action_woocommerce_checkout_process($wccs_custom_checkout_field_pro_process )
{
global $woocommerce;
//Add Fuel Surcharge & CAF
function woo_add_cart_fee() {
global $woocommerce;
if ( WC()->cart->cart_contents_total < 1500 &&
$_POST['delivery_type']=='Pick Up') {
$fuel_surchargeandCAF = get_option( 'fuel_surchargeandCAF',
70 );
WC()->cart->add_fee( __('Delivery Charges', 'woocommerce'),
$fuel_surchargeandCAF, TRUE, '');
}
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
};
add_action( 'woocommerce_checkout_process', 'action_woocommerce_checkout_process', 10,
1 );
Does anybody know how to disable the Postcode validation on the checkout page in WooCommerce?
I want to input 'text content' in "billing_postcode" field, but the shop says it's an invalid postcode.
Does anyone know how I can disable Postcode validation or allow text characters?
Just do this:
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 99 );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_postcode']['validate']);
unset($fields['shipping']['shipping_postcode']['validate']);
return $fields;
}
You can put this pretty much anywhere, but preferably in a custom plugin or in your theme's functions.php
You could try this:
add_filter( 'woocommerce_default_address_fields', 'custom_override_address_fields', 999, 1 );
function custom_override_address_fields( $address_fields ) {
// set as not required
$address_fields['postcode']['required'] = false;
// remove validation
unset( $address_fields['postcode']['validate'] );
return $address_fields;
}
I need to do extra step in the backend when a product is add to cart.
I need to get the product ID juste after it's add to the cart.
I use the woocommerce hook woocommerce_add_to_cart
add_action('woocommerce_add_to_cart', 'attach_item');
function attach_item() {
// I need to have the product id here.
}
I tried many way to get the ID but nothing work.
Any idea ...
Today I also get the same problem but I got the solution.
add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart',10,2 );
function woo_custom_add_to_cart( $cart_item_data,$productId ) {
var_dump($productId);
}
At the time of writing this, the hook is actually called from WooCommerce like so: (source)
do_action( 'woocommerce_add_to_cart', $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data );
Add your custom method like so:
add_action('woocommerce_add_to_cart', function($cartItemKey, $productId) {
// do sth with $productId
}, 10, 2);