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 an option to select cities inside shipping zones, for example to be able to set different prices per city.

Cities List

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

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

How to remove some cities from the list?
Update cities codes:

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 country code 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 quarters inside a city?
Create shipping zone with that city and restrict to the relevant postcodes, or (what is less recommended) split the city into areas (update city code and areas names) and in case the store is located iside the city update the store location in WooCommerce settings:

add_filter( 'woocommerce_states', 'csz_split_woocommerce_states', 30 );
function csz_split_woocommerce_states( $states ) {
	$city_code = 'AT90001';
	$sub_cities = array( __( 'Northern', 'woocommerce' ), __( 'Southern', 'woocommerce' ) );
	$count = 101;
	foreach ( $sub_cities as $sub_city ) {
		$states[ substr( $city_code, 0, 2 ) ][ $city_code . $count ] = $states[ substr( $city_code, 0, 2 ) ][ $city_code ] . ' - ' . $sub_city;
		$count++;
	}
	unset( $states[ substr( $city_code, 0, 2 ) ][ $city_code ] );
	return $states;
}

How to create cities list for unsupported country?
By its Local Census/UNLOCODE/HASC geocoded administrative divisions, cities names must be unique and without punctuation.

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

How to add 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).

Why the tax is not calculated on the distance fee?
Enter in the shipping method cost greater than zero.

Where the configured product distance fee will be displayed?
The product the fee will be added to its price and will be displayed in the subtotal of the mini cart widget.

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

Bulk Edit Tool

What is the required format?
Semicolon (;) between each city. For example: Wien; Rust; Steinbrunn

How to Modify cities in list to the required format?
Replace [\r\n]+ (regex) with ; in Notepad++.

How to enter all the locations within certain distance from a city with distances list?
Enter exclamation mark (!) followed by the city code, if necessary add minium and maximum distance seperated by semicolon (;).

Uninstall
  • Plugin Settings: Remove the countries.
  • WooCommerce Shipping Zones settings: Remove the locations.
  • Plugins: Deactivate and delete the plugin.
  • WooCommerce Settings: Update the store location.
  • Database: 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
WordPress

WordPress Popups

And the Jazz Artists.

Install the plugin.

In WooCommerce notify the customer product page about discount ineligibility since purchase not enough items from it- add the Auto Open trigger, targeting the desired product id page, and the custom conditions (update the product id and the quantity for discount):

add_filter( 'pum_get_conditions', 'condless_pum_cart_product_quantity_conditions' );
function condless_pum_cart_product_quantity_conditions( $conditions ) {
        return array_merge( $conditions, array(
                'password_page_unlocked' => array(
                        'group'    => __( 'Products', 'woocommerce' ),
                        'name'     => __( 'Products', 'woocommerce' ) . ': ' . __( 'Cart', 'woocommerce' ) . ' ' . __( 'Quantity', 'woocommerce' ),
                        'callback' => 'cart_product_quantity',
                ),
        ) );
}
function cart_product_quantity() {
        foreach ( WC()->cart->get_cart() as $cart_item ) {
                if ( '772' === $cart_item['product_id'] && 3 > $cart_item['quantity'] ) {
                                return true;
                }
        }
        return false;
}

In WooCommerce update the customer while purchase temporary out of stock product (for simple products)- Enable the “Add To Cart button classes” and “Shortcodes” options in the plugin, create popup with the name simple_is_on_backorder1, targeting All Products, in the content insert the [current_add_to_cart] shortcode and notification about that he gonna add product which is temporary out of stock, if AJAX archive page option is enabled create another popup with trigger Click Open on .archive_is_on_backorder1 and the option “do not prevent…” and notification about that he just added product which is temporary out of stock, if not use the code:

add_filter( 'woocommerce_loop_add_to_cart_args', 'condless_add_class', 10, 2 );
function condless_add_class( $args, $product ) {
	if ( $product->is_type( 'simple' ) && $product->is_on_backorder() && ! is_product() && 'no' === get_option( 'woocommerce_enable_ajax_add_to_cart' ) ) {
		$product_id = $product->get_id();
		$args['class'] .= ' popmake-archive_backorder-' . $product_id;
		if ( isset( $product->get_availability()['availability'] ) ) $out = '<div>' . $product->get_availability()['availability'] . '</div>' . '<a href=' . $product->add_to_cart_url() . '>' . $product->add_to_cart_text() . '</a>';
		echo do_shortcode( "[popup id='archive_backorder-" . $product_id . "']" . $out . "[/popup]" );
	}
	return $args;
}

As you probably have noticed- Pastorius, Carter, Valdés, and all other WordPress Version names, are names of popular jazz artists, inspired by WordPress core developers, who share a love of jazz music.

Categories
WordPress

WordPress Auto Generate Post

And Back to the Future.

Create post for a user when purchase some product (update the product ID):

add_action( 'woocommerce_order_status_completed', 'condless_create_page' );
function condless_create_page( $order_id ) {
	foreach ( wc_get_order( $order_id )->get_items() as $item ) {
		if ( '9' === $item->get_product_id() ) {
			$user_id = wc_get_order( $order_id )->get_user_id();
			$user = new WP_User( $user_id );
			$user->remove_role( 'customer' );
			$user->add_role( 'author' );
			wp_insert_post( array( 'post_title' => 'My New Page', 'post_status' => 'publish', 'post_author' => $user_id, 'post_type' => 'post') );
		}
	}
}

As you probably have noticed- Jigowatt ltd, the developers of Jigoshop on which WooCommerce code is based, was named after the pronunciation mistake of the word Gigawatt in the movie Back to the Future.

Categories
WooCommerce

WooCommerce Sell Media

And The University of the People.

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

  • Follow the guide
  • Add in the product’s “Purchase note” field link to the page the media embedded in
  • Enable content protection with the plugin
  • In case the media is stored in the website’s media folder prevent direct access to it, disable directory listing and hotlinking with the plugin
  • Limit connection to only one device with the plugin
  • Activate Two-factor authentication

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.