Add Any Attachment To WooCommerce Order Emails

To add an attachment to your order emails, open the functions.php file of your active theme and add the following snippet of code:

add_filter( 'woocommerce_email_attachments', 'webroom_attach_to_wc_emails', 10, 3);
function webroom_attach_to_wc_emails ( $attachments , $email_id, $object ) {

	// Avoiding errors and problems
    if ( ! is_a( $order, 'WC_Order' ) || ! isset( $email_id ) ) {
        return $attachments;
    }
  
	$file_path = get_template_directory() . '/file.pdf'; // directory of the current theme

 	// if you are using a child theme, use this line instead to get the directory
 	// $file_path = get_stylesheet_directory() . '/file.pdf';

	$attachments[] = $file_path;
	return $attachments;
}

Reference: https://www.webroom.tech/add-an-attachment-in-woocommerce-emails/

Move product “Additional Information” tab inside “Description” Tab in WooCommerce

The code below ( active theme’s funstions.php file ) will move the additional information tab in WooCommerce products to display the content under the “description” tab. Please feel free to add CSS to make them fit.

// Remove additional information tab
add_filter( 'woocommerce_product_tabs', function( $tabs ) {
	unset( $tabs['additional_information'] );
	return $tabs;
}, 98 );

// Insert additional information into description tab
add_filter( 'woocommerce_product_tabs', function( $tabs ) {
	$tabs['description']['callback'] = function() {
		global $product;
		wc_get_template( 'single-product/tabs/description.php' );
		if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
			wc_get_template( 'single-product/tabs/additional-information.php' );
		}
	};
	return $tabs;
}, 98 );

Reference: https://wpexplorer-themes.com/total/snippets/move-woocommerce-additional-information/

react-and-macOS

Install And Set Up React On MacOS X

Here I am going to explain the installation and setting up of React on macOS X Operating System locally.

  1. Install and Update with Homebrew
    Homebrew is a popular package manager for macOS. We can install all the packages and dependencies required to install React using Homebrew.

To install Homebrew, open the Terminal and run the command below.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

So after install, we need to update it

brew update
  1. Install Nodejs
    NPM will be installed with Nodejs itself. Nodejs can be installed using the below command.
brew install node
  1. Install Create-React-App Tool
    Now we need to install a tool named create-react-app using NPM as global.
npm install -g create-react-app
  1. Create a New React Project
    After create-react-app, we can create first react application.
create-react-app learn-react

Here learn-react is the name for the project.

  1. Running the Application
cd learn-react
npm start

This will opens up the react application in a new tab of the browser

http://localhost:3000

Thats all.

All command line actions are together bellow.

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install”

brew update
brew install node
brew upgrade node (to upgrade)
npm install -g create-react-app
npm install -g npm (to upgrade)
create-react-app learn-react
cd learn-react/
npm start

Reference:

https://www.techomoro.com/how-to-install-and-set-up-react-on-macos-x/

docker container keep restarting

I had an issue that the docker container keep restarting and not able to acces the local environment for my Magento 2.3.3. There are few alternatives but the following one resolved my issue.

Procedure
#1. Stop the container(s) using the following command:
docker-compose down
#2. Restart the containers using the following command:
docker-compose up -d

If you still face the issue then please try to follow the following steps:

How to Do a Clean Restart of a Docker Instance
If you are using Docker-Machine, make sure your are talking to the right one. Execute the command docker-machine ls to find which one is currently active.

It is also recommended to always redo the command:
eval “$(docker-machine env docker-machine-name)”


Note: Deleting volumes will wipe out their data. Back up any data that you need before deleting a container.


Procedure
#1. Stop the container(s) using the following command:
docker-compose down
#2. Delete all containers using the following command:
docker rm -f $(docker ps -a -q)
#3. Delete all volumes using the following command:
docker volume rm $(docker volume ls -q)
#4. Restart the containers using the following command:
docker-compose up -d

Reference: How to Do a Clean Restart of a Docker Instance

Magento 2 with Docker for local development

Finally it’s time to start developing for Magento 2 and here I am going to tell the issue I faced during setup and the solution what I did along with the reference links.

The following link will give the details information to setup the dev environment

Magento+Docker

but you you face issue such as:

Invalid credentials for ‘https://repo.magento.com/packages.json’, aborting.

Although you have entered the right credentials then just check you auth.json file , you might have default keys set there. For my case I had wrong key and I had a big trouble to find it out.

mkdir ~/.composer

vi ~/.composer/auth.json

The file will open and now you can add your keys for repo.magento.com

{
  "http-basic": {
        "repo.magento.com": {
            "username": "<public key>",
            "password": "<private key>"
        }
    }
}

To save the edits you have made, but leave vi running and your file open:

  1. Press <Esc>.
  2. Type :w
  3. Press <Return>.

To quit vi, and discard any changes your have made since last saving:

  1. Press <Esc>.
  2. Type :q!
  3. Press <Return>.

auth.json issue link.

And try again to run the magento2-install . Have fun !!

hsts issue on chrome – macOS catalina

The issue is really made me crazy while it’s happened on my local environment after upgrade my MacOS to catalina 10.15.2.

I have already followed the following article but still it was issue to access the local dev on my Mac => How to Delete HSTS Settings in Chrome

The fix is to type the word “thisisunsafe” once you get to the page that says “Your connection is not private” . Just click somewhere on the page and then blindly type thisisunsafe. This will immediately bypass the warning. Please don’t do on sites you don’t trust.

Which I found the following article to avoid the issue easily.

Product option price error in Magento 1.9.4

REASON OF THE ERROR

Magento moved a Product.OptionsPrice class constructor from varien/product.js to varien/product_options.js.

Also, they added this file to the product page via layouts:

app\design\frontend\rwd\default\layout\catalog.xml

app\design\frontend\base\default\layout\catalog.xml

<action method=”addJs”>varien/product_options.js</action>

As a result, after you update your Magento version, product.js file does not include code with Product.OptionsPrice initialization any more.

HOW TO FIX THE ERROR

Therecommend the following workflow:

  1. go to app\design\frontend\yourpackage\yourtheme\layout\catalog.xml
  2. find <catalog_product_view translate=”label”> section, and
  3. insert <action method=”addJs”>varien/product_options.js</action> …… after this line: <action method=”addJs”>varien/product.js</action>

Don’t forget to flush Magento cache after these actions.

Ref: https://amasty.com/blog/product-optionsprice-error-magento-1-9-3-1-fix/

Sequel Pro error when importing database

When I was trying to import an external database to setup my local working environment in Sequel Pro, I often get this ‘file read error’: 

An error occurred when reading the file, as it could not be read in the encoding you selected (Autodetect – Unicode (UTF-8)).

Solution:

To solve this issue, need to delete all the tables and try again with encoding ‘Western: Mac OS Roman’. As like the picture below.

phpBB: localhost redirects to my live site

To test on localhost with an existing database, you must also change the database table ‘config’.

config_name         config_value (from)       config_value (to)
"cookie_domain";    "example.com"             "localhost url"
"server_name";      "www.example.com"         "localhost url"
"server_protocol"   "https://"                "http://"
"site_home_url"     "https://www.example.com/" "http://localhost url/"
"script_path"       "/"                        "/"

Also need to change the config.php from root.

<?php
// phpBB 3.0.x auto-generated configuration file
// Do not change anything in this file!
$dbms = 'mysql';
$dbhost = 'localhost';
$dbport = '';
$dbname = 'REMOVED';
$dbuser = 'REMOVED';
$dbpasswd = 'REMOVED';
$table_prefix = 'phpbb_';
$acm_type = 'file';
$load_extensions = '';

@define('PHPBB_INSTALLED', true);
@define('DEBUG', true);
@define('DEBUG_EXTRA', true);
?>

How to install Composer on MacOS

There is some ways to install it. I will describe the way with Brew.

If you don’t have a brew, let’s do the followings…

It’s very easy to install brew. You have to run only your terminal and paste this code:

Step1 Install brew:

/usr/bin/ruby \
-e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

What does that code do here ?
1. Get script from https://raw.githubusercontent.com/Homebrew/install/master/install
2. Do it by using ruby

Step2 Install Composer:

brew install composer

Step3 check the version:

composer –version

Ref Link:

https://pilsniak.com/install-composer-mac-os/