WordPress

wordpress change post thumbnail size

Change post thumbnail size To change post thumbnail size, First check your theme support function add_theme_support(‘post-thumbnails’); Default WordPress Thumbnail the_post_thumbnail( ‘thumbnail’ ); // Thumbnail (150 x 150 hard cropped) the_post_thumbnail( ‘medium’ ); // Medium resolution (300 x 300 max height 300px) the_post_thumbnail( ‘medium_large’ ); // Medium Large (added in WP 4.4) resolution (768 x 0 […]

WooCommerce get all products

WooCommerce get all products $products = wc_get_products( array( ‘status’ => ‘publish’, ‘limit’ => -1 ) ); foreach ( $products as $product ){ echo  $product->get_status();  // Product status echo  $product->get_type();  // Product type echo  $product->get_id();    // Product ID echo  $product->get_title(); // Product title echo  $product->get_slug(); // Product slug echo  $product->get_price(); // Product price echo  $product->get_catalog_visibility(); // Product visibility echo  $product->get_stock_status(); // Product stock status // product date information echo $product->get_date_created()->date(‘Y-m-d H:i:s’); echo $product->get_date_modified()->date(‘Y-m-d H:i:s’); }   blog.qaisarsatti.com/woocommerce/woocommerce-get-all-products/

get all products with php in Woocommerce WordPress

Get all products with php in Woocommerce WordPress require_once(‘../wp-load.php’); global $wpdb; // Get 10 most recent product IDs in date descending order. $query = new WC_Product_Query( array( ‘limit’ => -1 , ‘status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ ) ); $products = $query->get_products(); foreach ( $products as $product ){ //print_r($products); //$pro_id = $product->get_id(); […]

WooCommerce Products Export to CSV via PHP

WooCommerce Products Export to CSV via PHP <?php require_once(‘../wp-load.php’); global $wpdb;   // Get 10 most recent product IDs in date descending order. $query = new WC_Product_Query( array( ‘limit’ => -1 , ‘status’ => ‘publish’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ ) ); $products = $query->get_products(); //print_r($products); // while ( $products->have_posts() ) : $products->the_post(); // […]

How to Enable HTTP Strict Transport Security (HSTS) in WordPress

Enable HTTP Strict Transport Security (HSTS) in WordPress Add the following code into your theme’s functions.php /** * Enables the HTTP Strict Transport Security (HSTS) header in WordPress. */ function tg_enable_strict_transport_security_hsts_header_wordpress() { header( ‘Strict-Transport-Security: max-age=31536000’ ); } add_action( ‘send_headers’, ‘tg_enable_strict_transport_security_hsts_header_wordpress’ ); Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security

Resize contact form 7 textarea rows and columns

Change Contact form 7 textarea rows & columns Code [textarea* message id:contact_message 10×2 placeholder “Your Message”] Result <textarea name=”message” cols=”10″ rows=”2″ class=”wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required” id=”contact_message” aria-required=”true” aria-invalid=”false” placeholder=”Your Message”></textarea> Sources: contactform7.com/text-fields/#textarea stackoverflow.com/questions/29025956/wordpress-contactform7-textarea-cols-and-rows-change-in-smaller-screens

Add “Where Did You Hear About Us” option in customer invoice email in WordPress

Add “Where Did You Hear About Us” option in WordPress #Add the following code on functions.php to add “How did you find us” option in customer invoice email in WordPress // For display and saving in order details page. <?php add_action( ‘add_meta_boxes’, ‘add_shop_order_meta_box’ ); function add_shop_order_meta_box() { add_meta_box( ‘custom_column’, __( ‘Customer Source’, ‘your_text_domain’ ), ‘shop_order_display_callback’, ‘shop_order’ […]

Add New Fields to the Order Details Metabox in WordPress

  // For display and saving in order details page. add_action( ‘add_meta_boxes’, ‘add_shop_order_meta_box’ ); function add_shop_order_meta_box() { add_meta_box( ‘custom_column’, __( ‘Customer Source’, ‘your_text_domain’ ), ‘shop_order_display_callback’, ‘shop_order’ ); } function shop_order_display_callback( $post ) { $meta = get_post_meta($post->ID,’customersource’, true); echo ‘ <div class=”customer_sourse_area”><div class=”customer_sourse_label”>Where did you hear about us?</div></div> ‘; if($meta){ //$value = get_post_meta( $post->ID, ‘Amouse Order […]

Author Templates – WordPress | Author page

WordPress author page Linking to Author Pages from Posts <p>Written by: <?php the_author_posts_link(); ?></p> List of Authors with Links <h2>List of authors:</h2> <ul> <?php wp_list_authors(); ?> </ul> Which Template File is Used? author-{nicename}.php – If the author’s nice name were rami, WordPress would look for author-rami.php. author-{id}.php – If the author’s ID were 6, WordPress would look for author-6.php. author.php archive.php index.php Using […]

Simple WordPress Loop

The Loop <?php if ( have_posts() ) { while ( have_posts() ) { the_post(); <!– Test if the current post is in category 3. –> <!– If it is, the div box is given the CSS class “post-cat-three”. –> <!– Otherwise, the div box is given the CSS class “post”. –> <?php if ( in_category( […]

How to Disable Gutenberg in WordPress and Keep the Classic Editor

How to Disable Gutenberg and Keep the Classic Editor in WordPress Install and activate the Classic Editor plugin. Go to the Settings » Writing page in your WordPress admin area. Select Classic editor from Default editor for all users. You can also Disable Gutenberg Editor & Widget completely with Disable Gutenberg plugin.

How to get Data from CSV file and update Woocommerce products with a script

  <?php require_once(‘../wp-load.php’); global $wpdb; // $product_ids=array(18744); // foreach($product_ids as $ak=>$product_id){ // $product = wc_get_product( $product_id ); // $product->set_name(‘Hello 2’); // $product->set_stock_quantity(‘9999’); // $product->set_slug(‘test-‘.$product_id); // $product->set_price(’50’); // $product->set_regular_price(‘5’); // //$product->set_sale_price(‘4’); // //$product->save(); // }   $row = 0; if (($handle = fopen(“test.csv”, “r”)) !== FALSE) { while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) { […]