Categories
WordPress

WooCommerce

And Back to the Future.

WooCommerce is an open source E-commerce software which comes as a plugin for WordPress, it is the most popular way of creating E-commerce websites. From many clearing options, order management, shipping types to inventory settings, the plugin covers all the requirements that may arise in creating E-commerce websites.

To edit the mobile menu button text in Storefront theme:

add_filter( 'storefront_menu_toggle_text', 'condless_storefront_menu_toggle_text' );
function condless_storefront_menu_toggle_text( $text ) {
	$text = __( 'My menu' );
	return $text;
}

To edit the Update cart button text in mobile:

add_filter( 'gettext', 'condless_change_update_cart_text', 20, 3 );
function condless_change_update_cart_text( $translated, $text, $domain ) {
if ( wp_is_mobile() && is_cart() && $translated == 'Update cart' ) {
$translated = 'Text for mobile';
}
return $translated;
}

Auto change the order status from “On hold” to “Processing”, for example, to allow a customer who pay in bank transfer (which take some time) to view the digital product download link on the “Order Received” page (must refresh the page):

add_action( 'woocommerce_thankyou', 'condless_woocommerce_auto_processing_orders' );
function condless_woocommerce_auto_processing_orders( $order_id ) {
    if ( ! $order_id )
        return;
    $order = wc_get_order( $order_id );
    if( $order->has_status( 'on-hold' ) ) {
        $order->update_status( 'processing' );
    }
}

Reordering checkout fields:

add_filter( 'woocommerce_checkout_fields', 'condless_reordering_checkout_fields' );
function condless_reordering_checkout_fields( $fields ) {
    $billing_order = array(
        'billing_first_name',
        'billing_last_name',
        'billing_email',
        'billing_phone',
        'billing_company',
        'billing_address_1',
        'billing_address_2',
        'billing_postcode',
        'billing_city',
        'billing_state',
        'billing_country'
    );
    $count = 0;
    $priority = 10;
    foreach($billing_order as $field_name){
        $count++;
        $fields['billing'][$field_name]['priority'] = $count * $priority;
    }
    $fields['billing']['billing_email']['class'] = array('form-row-first');
    $fields['billing']['billing_phone']['class'] = array('form-row-last');
    $fields['billing']['billing_postcode']['class'] = array('form-row-first');
    $fields['billing']['billing_city']['class'] = array('form-row-last');
    return $fields;
}

Hiding some variations of product:

add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'condless_hide_dropdown_variation_args', );
function condless_hide_dropdown_variation_args( $args ) {
    $args['show_option_none'] = false;
    foreach( $args['options'] as $key => $option ){
        if( $option === "2,5 kg" ) {
            unset($args['options'][$key]);
        }
    }
    return $args;
}

Add fields validation in the checkout page. for example, to allow ASCII chars only (as well as disallow non-English letters):

add_action( 'woocommerce_after_checkout_validation', 'condless_ascii_validate_checkout', 10, 2 );
function condless_ascii_validate_checkout( $fields, $errors ){
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'billing_first_name' ] ) )
$errors->add( 'validation', '<strong>Billing First name</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'billing_last_name' ] ) )
$errors->add( 'validation', '<strong>Billing Last name</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'billing_company' ] ) )
$errors->add( 'validation', '<strong>Billing Company</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'billing_address_1' ] ) )
$errors->add( 'validation', '<strong>Billing Address</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'billing_address_2' ] ) )
$errors->add( 'validation', '<strong>Billing Address details</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'billing_city' ] ) )
$errors->add( 'validation', '<strong>Billing City</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'shipping_first_name' ] ) )
$errors->add( 'validation', '<strong>Shipping First name</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'shipping_last_name' ] ) )
$errors->add( 'validation', '<strong>Shipping Last name</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'shipping_company' ] ) )
$errors->add( 'validation', '<strong>Shipping Company</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'shipping_address_1' ] ) )
$errors->add( 'validation', '<strong>Shipping Address</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'shipping_address_2' ] ) )
$errors->add( 'validation', '<strong>Shipping Address details</strong> contains non-English letters.' );
if ( preg_match( '/[^[:ascii:]]/', $fields[ 'shipping_city' ] ) )
$errors->add( 'validation', '<strong>Shipping City</strong> contains non-English letters.' );
}

Manipulate the product price display, for example, to display the discount on sale products:

add_filter( 'woocommerce_get_price_html', 'condless_simple_product_price_format', 10, 2 );
function condless_simple_product_price_format( $price, $product ) {
   if ( $product->is_on_sale() && $product->is_type('simple') ) {
      $price = sprintf( __( '<div class="was-now-save"><div class="was">WAS %1$s</div><div class="now">NOW %2$s</div><div class="save">SAVE %3$s</div></div>', 'woocommerce' ), wc_price ( $product->get_regular_price() ), wc_price( $product->get_sale_price() ), wc_price( $product->get_regular_price() - $product->get_sale_price() )  );      
   }
   return $price;
}

Display the TAX/VAT amount and the product price with/without it:

add_filter( 'woocommerce_get_price_suffix', 'condless_price_vat_suffix', 10, 4 );
function condless_price_vat_suffix( $html, $instance, $price, $qty ) {
if ( is_product() ) {
        $html .=  ' + ' . wc_price(wc_get_price_including_tax($instance) - wc_get_price_excluding_tax($instance)) . ' VAT =  ' . wc_price(wc_get_price_including_tax($instance)); }
return $html;
}

Remove the product added/removed messages:

add_filter( 'wc_add_to_cart_message_html', '__return_null' );
add_filter( 'woocommerce_cart_item_removed_notice_type', '__return_null' );

Display only products in built-in WordPress search results:

add_filter('pre_get_posts','condless_search_wc');
function condless_search_wc( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', 'product' );
}
return $query;
}

To allow only one item from the product to be bought in a single order, when low stock threshold:

add_filter( 'woocommerce_is_sold_individually', 'condless_wc_remove_quantity_fields', 10, 2 );
function condless_wc_remove_quantity_fields( $return, $product ) {
	if ( $product->get_stock_quantity() <= $product->get_low_stock_amount() )
  		return true;
}

To set up minimum payment for purchase with shipping, write in the “Cost” field (replace $min_order with your value):

$min_order - [fee percent="100" max_fee="$min_order"]

Popup creator. For example notifying the customer in product page about discount ineligibility since purchase not enough items from it, add the Auto Open trigger and the 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' ),
                        'name'     => __( 'Products: Cart Quantity' ),
                        'callback' => 'cart_product_quantity',
                ),
        ) );
}
function cart_product_quantity() {
        foreach ( WC()->cart->get_cart() as $cart_item ) {
                if ( $cart_item['product_id'] == 772 && $cart_item['quantity'] < 3 ) {
                                return true;
                }
        }
        return false;
}

Conditional shipping methods.

Booking and Appointments.

Wholesale.

Products personalization.

Recover abandoned carts.

Apply coupons automatically.

Shipment tracking.

Payment methods for payment apps which don’t have API.

Fees and discounts by payment method.

Payment method by product.

Request for quote payment option.

Advanced pricing.

Products filter.

Crowdfunding.

Bulk edit for variable products.

Multi vendor.

Selling digital media access (video courses, images, music, content), create virtual product for each media file with direct link to it / to the page on which it is embedded (use Vimeo Plus for heavy videos), restrict the media files / relevant pages that only those who purchased the compatible product on the WooCommerce may view it, enable content protection, limit connection to only one device, and activate 2FA.

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
WordPress

WordPress RTL

And the Engraved Stone.

WordPress and WooCommerce support right to left languages such as Arabic, Persian, and Urdu.

To edit CSV files with non-English letters, encode it to UTF-8 using Notepad / Google Sheets.

To fix WordPress build-in code block, use the CSS:

pre.wp-block-code {
	text-align: left;
	direction: ltr;
}

To fix Owl Carousel based slider elements, use the CSS:

.owl-carousel,
.bx-wrapper { direction: ltr; }
.owl-carousel .owl-item { direction: rtl; }

To fix Chosen Drop based dropdown elements, use the CSS:

.chosen-container .chosen-drop { left: 9999px; }

To create Twenty Twenty child theme, create the path wp-content/themes/twentytwenty-child, and create inside the files style.css and style-rtl.css with the content:

/*
 Theme Name:   twentytwenty Child
 Template:     twentytwenty
*/

And the file functions.php with the content:

<?php
add_action( 'wp_enqueue_scripts', 'condless_theme_enqueue_styles' );
function condless_theme_enqueue_styles() {
        if ( is_rtl() ) {
                wp_enqueue_style( 'parent-style-rtl', get_template_directory_uri() . '/style-rtl.css' );
        }
        else {
                wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
        }
}

To create Storefront child theme, create the path wp-content/themes/storefront-child, and create inside the files style.css and style-rtl.css with the content:

/*
Theme Name: Storefront Child
Template: storefront
*/

And the file functions.php with the content:

<?php
add_action( 'wp_enqueue_scripts', 'condless_theme_enqueue_styles', 9999 );
function condless_theme_enqueue_styles() {
	if ( is_rtl() ) {
        	wp_dequeue_style( 'storefront-child-style' );
		wp_enqueue_style( 'child-style-rtl', get_stylesheet_directory_uri() . '/style-rtl.css', 'storefront-style' );
	}
}

As you probably have noticed- most of the Middle Eastern languages are written from right to left, it is suggested that as stone was the main material used, it being easier to chisel right to left. With ink, suggestions continue, moving left to right prevented smudging.

Categories
WordPress

WordPress

And the Jazz Artists.

WordPress is an open source content management system. This system is the most popular CMS due to the great flexibility it provides and the option to manage a site even without extensive programming knowledge.

A significant option in WordPress is to create a Multisite network, ie multiple sites based on the same code, making it easier to manage and maintain them.

To improve system security at the server level: Update frequently, choose passwords at least 8 characters long (lower and upper case alphabets, numbers and symbols) and replace them frequently, verify that there is a firewall and DDOS protection, and config the Intrusion Prevention System (enable mod_remoteip if used with reverse proxy), set up hiding of the web server details, scan the server files and pass on the logs frequently.

To improve system security at the WordPress level: Update frequently, report any suspicious activity in your account to your hosting provider, use the build-in tool “Site Health”, install few plugins as possible, remove unused themes, install SSL certificate, set up Two-Factor Authentication, and disable the themes and plugins editors by adding the directive to wp-config.php file:

define( 'DISALLOW_FILE_EDIT', true );

Disable the XML-RPC function and the directory browsing option by adding the directives to the .htacess file:

<Files "xmlrpc.php">
Order Allow,Deny
Deny from all
</Files>

Options -Indexes

And disable PHP execution in the uploads directory by creating inside a .htaccess file with the content:

<Files "*.php">
Order Deny,Allow
Deny from All
</Files>

Scan frequently the code in the WordPress directory and database for malwares detection and delete unused items, create full backup before each modification, consider reinstalling WordPress (core files, themes and plugins) from the Dashboard. Make use of the recently modified files command:

find ./ -type f -mtime -15

To remove the Mobile Spam Popup malware, delete the wp-tmp.php, wp-vcd.php, wp-feed.php files from wp-includes directory and delete the code which is creating them from the themes’ functions.php.

To remove the Japanese Keyword Hack malware, clean the malicious code from .htaccess, wp-config.php, sitemap.xml files and uploads directory.

To run WordPress website with SSL in reverse proxy, add the directive to wp-config.php (above “That’s all, stop editing!”):

$_SERVER['HTTPS'] = 'on';

To workaround the loopback error while using the Theme Editor, edit the theme while another theme is temporarily active.

To improve the SEO for the WordPress: use responsive template, config permalink by post name and the media path without date, set the URL slugs in English, and speed up the WordPress.

To optimize the WordPress Speed: Turn off Trackbacks & Pingbacks, decrease media size before upload, disable posts Update Services, and limit autosaves and revisions by adding the directives to the wp-config.php file:

define('AUTOSAVE_INTERVAL', 300 );
define('WP_POST_REVISIONS', false );

To control the file storage and upload size limit, the available space on the server, the size of the hosting plan, the hosting panel settings, the WordPress multisite settings, and the files (located in multiple locations): php.ini, .user.ini, .htaccess, wp-config.php, functions.php.

To change theme files in WordPress, create child theme. To change WordPress functionality, use built-in hooks (which are seperated to actions and filters), add the hooks into child theme’s functions.php. To change WordPress styles, use the Dashboard => Appearance => Customize => Additional CSS, and in order the change the styles of the Dashboard itself:

add_action( 'admin_head', 'condless_admin_custom_css' );
function condless_admin_custom_css() { 
	echo '<style>
	// Your custom CSS
	</style>'; 
}

To customize the Twenty Twenty theme header structure, make use of the CSS:

.cover-header-inner-wrapper { min-height: 60vh !important; }
.home .entry-header { display: none; }
.home .post-inner { padding: 0; }

To limit the length of the code block, make use of the CSS:

pre.wp-block-code { max-height: 30vh; }

To use new fonts, make use of the CSS:

@font-face {
    font-family: $font_family_name;  
    src: url($font_url);  
    font-weight: normal;
}

* { font-family: $font_family_name, Arial, sans-serif; }

To limit post/page creation for author:

add_filter( 'wp_insert_post_empty_content', 'condless_cancel_post_save', 99, 2 );
function condless_cancel_post_save( $maybe_empty, $postarr ) {
	$post_query = new WP_Query( array( 'post_author' => $postarr[ 'post_author' ], 'post_type' => $postarr[ 'post_type' ], 'post_status' => array ( 'any', 'trash', 'draft' ) ) );
	if ( $postarr[ 'ID' ] == 0 && ( $postarr[ 'post_type' ] == 'page' || $postarr[ 'post_type' ] == 'post' ) && ! current_user_can( 'manage_categories' ) && $post_query->found_posts >= 3 ) {
		return true;
	}
	return $maybe_empty;
}

Enable use of session variables:

add_action( 'init', 'condless_activate_session', 1 );
function condless_activate_session() {
    if( ! session_id() ) {
        session_start();
    }
}

E-commerce.

Tags for effective social media sharing.

Contact forms. For custom design, make use of the CSS:

.wpcf7-form {
	background: #dcc8a5;
	padding: 10px 20px;
	border: 2px solid #f6efdf;
	border-radius: 7px;
	max-width: 300px;
}
 
.wpcf7-form p {
	color: #4f2a0f;
	margin-bottom: 5px;
}
 
.wpcf7-form input, .wpcf7-form textarea, .wpcf7-form select {
	background: #f6efdf;
	padding: 5px 7px;
	margin: 4px 0 8px 0;
	border: 3px solid #ccb58c;
	color: #4f4f4f;
	border-radius: 7px;
}
 
.wpcf7-form .wpcf7-submit {
	background: #4f2a0f;
	padding: 5px 15px;
	color: #fff;
	min-width: 100px;
}
 
.wpcf7-form input[type="submit"]:hover {
 	background: #000;
}

Multi language.

Forums with moderation options.

Social network with private area.

Ads board.

Slider. To create full width video, make use of the CSS:

.wp-video, video.wp-video-shortcode, .mejs-container, .mejs-overlay.load {
	width: 100% !important;
	height: 100% !important;
}
.mejs-container {
	padding-top: 56.25%;
}
.wp-video, video.wp-video-shortcode {
	max-width: 100% !important;
}
video.wp-video-shortcode {
	position: relative;
}
.mejs-mediaelement {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
}
.mejs-controls {
	display: none;
}
.mejs-overlay-play {
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	width: auto !important;
	height: auto !important;
}

Image hover effects.

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.