Skip to content

Instantly share code, notes, and snippets.

View hmowais's full-sized avatar
🎯
Focusing

HM Owais hmowais

🎯
Focusing
  • Karachi, Pakistan
View GitHub Profile
@hmowais
hmowais / functions.php
Created November 27, 2019 11:44
Remove Woocommerce Products Buttons in Avada Theme
<?php
function remove_woo_commerce_hooks() {
global $avada_woocommerce;
if(is_home() || is_front_page()) :
remove_action( 'woocommerce_after_shop_loop_item', array( $avada_woocommerce, 'show_details_button' ), 15 );
remove_action( 'woocommerce_after_shop_loop_item', array( $avada_woocommerce, 'template_loop_add_to_cart' ), 10 );
endif;
}
add_action( 'wp', 'remove_woo_commerce_hooks' );
@hmowais
hmowais / functions.php
Created November 27, 2019 12:44
Show Custom Content After Product Price
<?php
function cw_change_product_price_display( $price ) {
if(is_singular()) {
$price .= '<small>' . ' Excl. GST' . '</small>';
return $price;
}
else {
$price .= '<small>' . ' Excl. GST' . '</small>';
return $price;
@hmowais
hmowais / functions.php
Created November 27, 2019 21:00
Modify WordPress Default Search (Add Product Sku's)
<?php
/** __________________________________ ENHANCE THE STANDARD SEARCH
* Join posts and postmeta tables
* This one hels to include the SKU in tzhe standard search
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() || !empty($_REQUEST['s'] )) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
@hmowais
hmowais / functions.php
Created December 2, 2019 06:15
Remove Avada Title bar on Woocommerce Single Product page
<?php
add_action( 'template_redirect', 'avada_check_page' );
function avada_check_page() {
if ( is_singular( 'product' ) ) {
add_action( 'avada_override_current_page_title_bar', 'avada_remove_title_bar' );
}
}
function avada_remove_title_bar() {
}
@hmowais
hmowais / functions.php
Created December 2, 2019 10:10
Remove Avada Hooks in Woocommerce
<?php
// https://theme-fusion.com/documentation/avada/woocommerce/override-avada-woocommerce-hooks/
function remove_woo_commerce_hooks() {
global $avada_woocommerce;
remove_action( 'woocommerce_single_product_summary', array( $avada_woocommerce, 'add_product_border' ), 19 );
}
add_action( 'after_setup_theme', 'remove_woo_commerce_hooks' );
@hmowais
hmowais / functions.php
Created December 11, 2019 12:27
Replace Woocommerce default image placeholder
<?php
/**
* Change the placeholder image
*/
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
// replace with path to your image
@hmowais
hmowais / functions.php
Created December 11, 2019 18:00
file exist in WordPress upload Folder
<?php
global $product;
$upload_dir = wp_upload_dir();
$file_location = $upload_dir['basedir'].'/'."acf_attached_file".'/'.$product->get_slug().'.pdf';
if(file_exists($file_location)) {
echo "file exist";
}
else {
echo "not exist";
@hmowais
hmowais / functions.php
Created December 18, 2019 11:25
Upload All PDF Files into Separate Folder
<?php
add_filter('wp_handle_upload_prefilter', 'pdf_pre_upload');
add_filter('wp_handle_upload', 'pdf_post_upload');
function pdf_pre_upload($file){
add_filter('upload_dir', 'pdf_custom_upload_dir');
return $file;
}
@hmowais
hmowais / functions.php
Created December 18, 2019 11:37
ACF file Upload to Seperate Folder
<?php
// ACF upload prefilter
function acf_upload_dir_prefilter($errors, $file, $field) {
$upload_dir = wp_upload_dir();
// only allow admin
if( !current_user_can('manage_options') ) {
$errors[] = 'Only administrators may upload attachments';
}
$_filter = false;
// This filter changes directory just for item being uploaded
@hmowais
hmowais / functions.php
Created December 18, 2019 12:06
Search by SKU | Variations also
<?php
add_filter('the_posts', 'variation_query');
function variation_query($posts, $query = false) {
if (is_search() && !is_admin())
{
$ignoreIds = array(0);
foreach($posts as $post)
{