Categories
WooCommerce

WooCommerce Product Edit Permission

And the Persian Mathematician.

Removal of the option to edit some fields for specific user role (update the fields and the user role):

add_action( 'add_meta_boxes_product', 'condless_remove_metaboxes_edit_product', 9999 );
function condless_remove_metaboxes_edit_product() {
	if ( ! current_user_can( 'manage_options' ) ) {
		remove_meta_box( 'postexcerpt', 'product', 'normal' );
		remove_meta_box( 'postimagediv', 'product', 'side' );
		remove_meta_box( 'woocommerce-product-images', 'product', 'side' );
	}
}

add_filter( 'woocommerce_product_data_tabs', 'condless_remove_tabs' );
function condless_remove_tabs( $tabs ) {
	if ( ! current_user_can( 'manage_options' ) ) {
		unset( $tabs['advanced'] );
	}
	return( $tabs );
}

As you probably have noticed- the source of the numbering system is India, the West was exposed to the method only in the 11th century, and mainly through the writings of the Persian Mathematician al-Khwarizmi, which the term “algorithm” was named after him.

Categories
WooCommerce

Advanced Options for WooCommerce

Install the plugin to add advanced options to WooCommerce.

Categories
WooCommerce

Cities Shipping Zones for WooCommerce

Install the plugin to add country’s cities list that will be used as shipping zones.

Cities List

How to modify cities names?
Update country, cities codes, and cities names:

add_filter( 'woocommerce_states', 'csz_modify_woocommerce_states', 40 );
function csz_modify_woocommerce_states( $states ) {
	$country = 'AT';
	$states[ $country ]['AT90001'] = 'Vienna';
	return $states;
}

How to remove some cities from the list?
Update the code of the cities for removal:

add_filter( 'woocommerce_states', 'csz_remove_woocommerce_states', 50 );
function csz_remove_woocommerce_states( $states ) {
	$unnecessary_cities = array( 'AT10101', 'AT10201', 'AT10301' );
	foreach ( $unnecessary_cities as $city ) {
		unset( $states[ substr( $city, 0, 2 ) ][ $city ] );
	}
	return $states;
}

How to keep only specific cities in the list?
Update the country and cities codes:

add_filter( 'woocommerce_states', 'csz_set_woocommerce_states', 20 );
function csz_set_woocommerce_states( $states ) {
	$country = 'AT';
	$cities = array( 'AT10101', 'AT10201', 'AT10301' );
	$new_states = array();
	foreach ( $cities as $city ) {
		if ( isset( $states[ $country ][ $city ] ) ) {
			$new_states[ $city ] = $states[ $country ][ $city ];
		}
	}
	$states[ $country ] = $new_states;
	return $states;
}

How to create shipping zones for areas inside a city?
Use zipcode, or split the city into sub-city areas which is less recommended (update country, cities codes, cities names):

add_filter( 'woocommerce_states', 'csz_split_woocommerce_states', 30 );
function csz_split_woocommerce_states( $states ) {
	unset( $states['AT']['AT90001'] );
	$states['AT'] += array(
		'AT900011' => 'Wien' . '- ' . __( 'Northern', 'woocommerce' ),
		'AT900012' => 'Wien' . '- ' . __( 'Southern', 'woocommerce' ),
	);
	return $states;
}

How to create cities list for a unsupported country?
By its Local Census/UNLOCODE/HASC geocoded administrative divisions, city name must be unique.

How to bulk edit the cities of certain shipping zone?
Use the Bulk Edit option, if the variable $country_states exist in the cities list file you may use states as well, pay attention to not write the same city twice.

Which additional uses shop owners make with the customer city?
Displaying certain products (filter by city category), selling certain products (plugin that limits by state), shipping certain products (associating the products to a class without price in the relevant shipping method), applying taxes (using the city code in the state field in the settings), enabling payment / shipping methods (conditional payment / shipping plugin).

Distance Fee

Given a (domestic) city’s distances list, will be possible to add distance based fee for the shipping rate or product price (for example- to sell moving services). Israel have few cities with built-in cities distances list.

How to set the Distance Fee?
WooCommerce Settings: Verify the store location is set for a country with distances list, Plugin Settings: set the distance fee, Shipping Method Settings: set price and enable the distance fee.

Why I can’t see the distance fee in the Checkout?
Resave any shipping method (in order to flush the cache).

How I shall organize the distances list for some city?
Use as index the locations codes or names (as they appear in the website), verify to set distance to the city itself.

How to enter all the locations that distance is configured for them from a specific city?
In the Bulk Edit option, enter the character ‘!’ followed by the city code (currently it doesn’t support distances list indexed not by the website language.

Uninstall
  • Remove the locations from WooCommerce Shipping Zones settings.
  • Deactivate and delete the plugin.
  • Update the store location in WooCommerce settings.
  • Consider to convert/erase the state field values of orders and users that were created/updated while the plugin was applied on the countries they belong to.
Categories
WordPress

WordPress Restrict Access

And The Little Trump.

Grant access to product pages for visitors only via the website search form:

add_action( 'template_redirect', 'condless_redirect' );
function condless_redirect() {
	if ( ! is_user_logged_in() && is_product() && strpos( wp_get_referer(), home_url() . '/?s' ) === false && wc()->cart->get_cart_contents_count() === 0 ) {
		wp_redirect( home_url() );
	}
}

Restrict submition to 1 form per email- install the pluginplugin and use:

add_filter( 'wpcf7_validate_email*', 'condless_email_validation_filter', 20, 2 );
function condless_email_validation_filter( $result, $tag ) {
	if ( Flamingo_Contact::find( array( 's' => trim( $_POST['your-email'] ) ) ) ) {
		$result->invalidate( $tag, __( 'Sorry, that email address is already used!' ) );
	}
        return $result;
}

Save attachments in folder restricted to logged-in users only- install the plugin, and plugin and create .htaccesss file in the wpcf7-submissions directory that inside the uploads directory with the content:

Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule ^(.*)$ - [R=403,L]

As you probably have noticed- unlike other WordPress default themes, the Twenty Twenty theme was written based on already existing theme, Chaplin by Anders Noren.

Categories
WooCommerce

WooCommerce Sell Media

And The University of the People.

Sell access to digital media (content pages, video courses, images, music):

  • Create page and embed the media in it
  • Create virtual product with direct link to the page
  • Restrict the items that only those who purchased the compatible product may access it with the plugin
  • Enable content protection with the plugin
  • Limit connection to only one device with the plugin
  • Activate Two-factor authentication
  • Disable directory listing with Options -Indexes in the .htaccess file

As you probably have noticed- distance learning occupies a growing part of the way of learning, the one that has taken it one step further, is the University of the People, which does not have a physical campus and offers a full online degree without tuition.