All Blog Posts

Redirect subscription add to cart to checkout page

Posted on September 27th, 2016 by Developers

/** * Redirect subscription add to cart to checkout page * * @param string $url */ function custom_add_to_cart_redirect( $url ) { $product_id = (int) $_REQUEST[‘add-to-cart’]; if ( class_exists( ‘WC_Subscriptions_Product’ ) ) { if ( WC_Subscriptions_Product::is_subscription( $product_id ) ) { return get_permalink(get_option( ‘woocommerce_checkout_page_id’ ) ); } else return $url; } else return $url; } add_filter(‘add_to_cart_redirect’, ‘custom_add_to_cart_redirect’);

Read More

Change add to cart button text

Posted on September 27th, 2016 by Developers

/** * Change the add to cart text on single product pages */ function woo_custom_cart_button_text() { return __(‘My Button Text’, ‘woocommerce’); } add_filter(‘single_add_to_cart_text’, ‘woo_custom_cart_button_text’); /** * Change the add to cart text on product archives */ function woo_archive_custom_cart_button_text() { return __( ‘My Button Text’, ‘woocommerce’ ); } add_filter( ‘add_to_cart_text’, ‘woo_archive_custom_cart_button_text’ );

Read More

Add a custom currency / symbol

Posted on September 27th, 2016 by Developers

add_filter( ‘woocommerce_currencies’, ‘add_my_currency’ ); function add_my_currency( $currencies ) { $currencies[‘ABC’] = __( ‘Currency name’, ‘woocommerce’ ); return $currencies; } add_filter(‘woocommerce_currency_symbol’, ‘add_my_currency_symbol’, 10, 2); function add_my_currency_symbol( $currency_symbol, $currency ) { switch( $currency ) { case ‘ABC’: $currency_symbol = ‘$’; break; } return $currency_symbol; }

Read More

Automatically add product to cart on visit

Posted on September 27th, 2016 by Developers

/* * Add item to cart on visit */ function add_product_to_cart() { if ( ! is_admin() ) { global $woocommerce; $product_id = 64; $found = false; //check if product already in cart if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) { foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) { $_product = $values[‘data’]; if ( […]

Read More

Empty cart

Posted on September 27th, 2016 by Developers

/* * Empty WooCommerce cart */ function my_empty_cart(){ global $woocommerce; $woocommerce->cart->empty_cart(); } add_action(‘init’, ‘my_empty_cart’);

Read More

Remove “Products” from breadcrumb

Posted on September 27th, 2016 by Developers

/* * Hide “Products” in WooCommerce breadcrumb */ function woo_custom_filter_breadcrumbs_trail ( $trail ) { foreach ( $trail as $k => $v ) { if ( strtolower( strip_tags( $v ) ) == ‘products’ ) { unset( $trail[$k] ); break; } } return $trail; } add_filter( ‘woo_breadcrumbs_trail’, ‘woo_custom_filter_breadcrumbs_trail’, 10 );

Read More

Replace default product placeholder image

Posted on September 27th, 2016 by Developers

/* * goes in theme functions.php or a custom plugin. Replace the image filename/path with your own ? * **/ add_action( ‘init’, ‘custom_fix_thumbnail’ ); function custom_fix_thumbnail() { add_filter(‘woocommerce_placeholder_img_src’, ‘custom_woocommerce_placeholder_img_src’); function custom_woocommerce_placeholder_img_src( $src ) { $upload_dir = wp_upload_dir(); $uploads = untrailingslashit( $upload_dir[‘baseurl’] ); $src = $uploads . ‘/2012/07/thumb1.jpg’; return $src; } }

Read More

Replace WooCommerce default PayPal logo

Posted on September 27th, 2016 by Developers

/* * Replace WooCommerce default PayPal icon */ function paypal_checkout_icon() { return ‘https://www.paypalobjects.com/webstatic/mktg/logo-center/logo_betalen_met_paypal_nl.jpg’; // write your own image URL here } add_filter( ‘woocommerce_paypal_icon’, ‘paypal_checkout_icon’ );

Read More

Add email recipient when order completed

Posted on September 27th, 2016 by Developers

function woo_extra_email_recipient($recipient, $object) { $recipient = $recipient . ‘, your@email.com’; return $recipient; } add_filter( ‘woocommerce_email_recipient_customer_completed_order’, ‘woo_extra_email_recipient’, 10, 2);

Read More

Redirect add to cart button to checkout page

Posted on September 27th, 2016 by Developers

add_filter (‘add_to_cart_redirect’, ‘redirect_to_checkout’); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; }

Read More