What does the double colon (::) in PHP means?

https://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php

The double colon is called the Scope Resolution Operator and is ” used to staticconstant, and overridden properties or methods of a class.”

//Exemple 1
class MyClass {
    const CONST_VALUE = 'A constant value';
}

$classname = 'MyClass';
echo $classname::CONST_VALUE; // As of PHP 5.3.0

echo MyClass::CONST_VALUE;
//Exemple 2
class OtherClass extends MyClass
{
    public static $my_static = 'static var';

    public static function doubleColon() {
        echo parent::CONST_VALUE . "\n";
        echo self::$my_static . "\n";
    }
}

$classname = 'OtherClass';
$classname::doubleColon(); // As of PHP 5.3.0

OtherClass::doubleColon();

WHERE clause with Special character in MySQL and PHP query and prepared statement

Special character issue in php query can be solved by using:

WHERE _utf8'string'

https://dev.mysql.com/doc/refman/8.0/en/string-literals.html

this unfortunately does not work for prepared statement.

Instead set the character set for the connection to utf-8 using

$conn->set_charset("utf8")

https://www.php.net/manual/en/mysqli.set-charset.php

if (!$conn->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $conn->error);
    exit();
} else {
    printf("Current character set: %s\n", $conn->character_set_name());
}

If your string might include backslash, escaping the string will do the trick:

$city = mysqli_real_escape_string($link, $city);

php.net/manual/en/mysqli.real-escape-string.php

Remove SKU from email

override email-order-items.php in your template and comment out the SKU line.

To remove SKU from invoice, override print-content.php (from the Print Invoice and Delivery Note for Woocommerce Plugin) and comment the content with the dt and dd element on line 199 and 200.

Remove SKU from order invoice and email in virtuemart

Here are the list of files to modify to remove sku from virtuemart, order, invoices and emails:

com_virtuemart/cart/default_pricelist.php

com_virtuemart/invoice/invoice_items.php

com_virtuemart/invoice/mail_html_pricelist.php

com_virtuemart/invoice/mail_raw_pricelist.php

com_virtuemart/orders/details_items.php

When modifying tables, change the product name column to colspan=”3″ where you find colspan=”2″

Make sure to create overrides in your template

If your template already have overrides for those then save your files before updating the template as they would be overriden.

Ideally make a copy of your template to not accidently erase your modification when updating your template.

Date and time in php: common function

Convert a date in a timestamp:

strtotime ( string $datetime [, int $now = time() ] ) : int

https://www.php.net/manual/en/function.strtotime.php

Add an arbitrary amount of time in a string format:

strtotime("+1 week"), "\n";

$availability_date=get_post_meta( get_the_ID(), 'availability date', true );
$date_string=strval($availability_date);
$date_string.=" +3 weeks";
$date=new DateTime;
$diplay_time= date('d-m-Y',strtotime($date_string)) ;
$availability_date=strtotime($availability_date);

Adding a custom field in a product page

1- Add a custom field in the backend

/**
*Add a custom field in the product data section of Woocommerce product.
*/
function cf_create_custom_field(){
 $args= array(
  'id'=>'custom_text_field_title',
  'label'=>__('Custom Text Field Title','cf'),
  'class'=>'cf-custom-field',
  'desc_tip'=>true,
  'description'=>__('Enter the description of your custom text field','cf'),
 );
woocommerce_wp_text_input($args);

}
add_action('woocommerce_product_options_general_product_date','cf_create_cutom_field');

You can find the list of accepted parameters here: https://github.com/woocommerce/woocommerce/blob/master/includes/admin/wc-meta-box-functions.php

Source: https://pluginrepublic.com/add-custom-fields-woocommerce-product/

/**
*Save the custom field
*/
function cf_save_custom_field($post_id){
  $product=wc_get_product($post_id);
  $title=isset($_POST['custom_text_field_title'])?$_POST['custom_text_field_title']:'';
  $product->update_meta_data('custom_text_field_title',sanitize_text_field($title));
  $product->save();
}
add_action('woocommerce_process_product_meta','cf_save_custom_field');
/*
*Display custom field on  the front end
*/
function cf_display_custom_field(){
  global $post;
  //Check for the custom field value
  $product=wc_get_product($post->ID);
  $title=$product->get_meta('custom_text_field_title');
  if ($title){
   //Only display our field if we've got a value for the field title
   printf(
   '<div class="cf-custom-field-wrapper"><label for ="cf-title-field">%s</label><input type="text" id="cf-title-field" name="cf-title-field" value=""></div>',
   esc_html($title)
   );
  }
}
add_action('woocommerce_before_add_to_cart_button','cf_display_custom_field');

Writing content

In case you have no idea about the content a page should have but you have to write it anyway, because you client absolutly want it or because there is an obvious use for such a landing page but you have no inspiration on the content, I present you with a methodology to write a text about a given topic whithout prior knowledge:

Take the few first search result pages and use it as inspiration for the page structure and content. Once you have an overview of the different elements that needs to feature on the page. You will have a better idea on how to layout the page.

With the example gathered from to pages you can now write a text that presents your topic/product/category correctly, using appropriate keyword and satisfying customer expectation and ansewering customer intent.

Even if the pages you use for inspiration or as source were ranking well they might be overooking important keyword or not be fully satisfying for the customer. So don’t hesitate to take further step in order to write better text using a more engaging layout.

Consult your analytic to find for user query using the target keyword(s) to check if customer have recurring question or associate your keyword with specific adjectives or query.

What is a “Final Class” in php?

“PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended”

https://www.php.net/manual/en/language.oop5.final.php#:~:text=PHP%205%20introduces%20the%20final,then%20it%20cannot%20be%20extended.&text=Note%3A%20Properties%20and%20constants%20cannot,may%20be%20declared%20as%20final.