If you want to get the count of posts in wordpress archive page, You can by 2 ways.
First option is
$count = $GLOBALS['wp_query']->post_count;
Another option is
$count = $GLOBALS['wp_query']->found_posts;
Have any doubt please comment here.
WordPress/PHP Developer Chennai
If you want to get the count of posts in wordpress archive page, You can by 2 ways.
First option is
$count = $GLOBALS['wp_query']->post_count;
Another option is
$count = $GLOBALS['wp_query']->found_posts;
Have any doubt please comment here.
For redirect non admin users to home page and disallow back end access in WordPress, you need to simply copy and paste the following code in your theme’s functions.php file.
function redirect_non_admin_user(){ if ( !defined( 'DOING_AJAX' ) && !current_user_can('administrator') ){ wp_redirect( site_url() ); exit; } } add_action( 'admin_init', 'redirect_non_admin_user' );
Have any doubt, then comment here!
To disable WooCommerce Payment methods based on cart item quantity, you need to simply copy and paste the following code in your theme’s functions.php file.
Here I’m unsetting the COD when cart item quantity limit reached 10.
add_filter('woocommerce_available_payment_gateways', 'disable_payment_gateway_based_on_quantity', 10, 1); function disable_payment_gateway_based_on_quantity( $available_gateways ) { $qty_limit = 10; $limit_reached = false; foreach(WC()->cart->get_cart() as $cart_item){ if($cart_item['quantity'] > $qty_limit ){ $limit_reached = true; break; } } if($limit_reached){ unset($available_gateways['cod']); } return $available_gateways; }
You can use the same code for disable WooCommerce Payment methods based on cart item quantity. Change quantity and payment method slug for your needs.
Have any doubt, then comment here!
You can check whether the folder is exits or not by using file_exists(). You can also create folder by using mkdir(). See below example code to create folder if it doesn’t already exits in PHP.
if (!file_exists('path/to/directory')) { mkdir('path/to/directory', 0777, true); }
Have any doubt, then comment here!
WordPress Hooks are the functions that can be applied to an Action or a Filter in WordPress.
Two types of hooks exist in WordPress. That are
Action hooks allow you to add additional code to the WordPress core or theme so that you can achieve some new functionality or customizations.
It can be handled by add_action() and do_action().
Filter hooks allow you to control how something happens or change something that’s already being output.
It can be handled by add_filter and apply_filter().
You can get the WordPress version using the following code:
$version=bloginfo('version'); echo $version;
Here $version displays the WordPress Version you use. You can get different information about the current site by passing parameters to bloginfo(). Some important parameter’s are listed below
Have any doubt, then comment here!
If you want to disable payment gateway for a specific country in WooCommerce then you have to decide the payment gateway and country code. Here I’m disabling the cod for India. You have to replace “cod” instead of your payment gateway. Have to replace “IN” instead of your decided country code. Place the following code in your functions.php file.
function disable_payment_gateway_for_a_country( $available_gateways ) { global $woocommerce; if ( isset( $available_gateways['cod'] ) && $woocommerce->customer->get_country() == 'IN' ) { unset( $available_gateways['cod'] ); } return $available_gateways; } add_filter( 'woocommerce_available_payment_gateways', 'disable_payment_gateway_for_a_country' );
Have any doubt, then comment here!
If you want to remove related products from product page in WooCommerce then place the following code in your functions.php file.
function wc_remove_related_products( $args ) { return array(); } add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);
Have any doubt, then comment here!
If you want to get number of items in a WooCommerce cart then you can place the following code in your file.
global $woocommerce; $count=$woocommerce->cart->cart_contents_count;
Here $count having total number of items in your WooCommerce cart.
Have any doubt, then comment here!
You can fetch shipping address by using WC_Order object and get_shipping_address() from order id.
Use the following code to fetch shipping address from order ID.
$order = new WC_Order( $order_id ); $shipping_address=$order->get_shipping_address();
Have any doubt, then comment here!