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/

The way to search through posts by ID in WordPress admin panel

Here we can do it ….

Please add the following code in your functions.php file.


add_action( 'parse_request', 'idsearch' );
function idsearch( $wp ) {
global $pagenow;

// If it's not the post listing return
if( 'edit.php' != $pagenow )
return;

// If it's not a search return
if( !isset( $wp->query_vars['s'] ) )
return;

// If it's a search but there's no prefix, return
if( '#' != substr( $wp->query_vars['s'], 0, 1 ) )
return;

// Validate the numeric value
$id = absint( substr( $wp->query_vars['s'], 1 ) );
if( !$id )
return; // Return if no ID, absint returns 0 for invalid values

// If we reach here, all criteria is fulfilled, unset search and select by ID instead
unset( $wp->query_vars['s'] );
$wp->query_vars['p'] = $id;
}

All you then do is search using the regular search box using a #(hash) prefix infront of the numeric ID.

#123

..would return the post with an ID of 123.

Ref: https://wordpress.stackexchange.com/questions/9276/search-posts-by-id-in-admin

How to Add Facebook Open Graph Meta Data for Facebook share in WordPress

<?php if (is_single()) {
if (has_post_thumbnail($post->ID)) {
$thumbid = get_post_thumbnail_id($post->ID);
$postimg = wp_get_attachment_image_src($thumbid, array(500, 500));
$postimg = $postimg[0];
} else {
//$postimg = get_bloginfo('template_url') . "/images/d_facebook.png";
}
$og_url = get_permalink($post); ?>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>"/>
<meta property="og:title" content="
<?php the_title(); ?>"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="<?php echo $og_url; ?>"/> <meta property="og:description" content="<?php echo htmlspecialchars(get_the_excerpt()); ?>"/>
<meta property="og:image" content="<?php echo $postimg; ?>"> <?php }?>