Skip to content

Instantly share code, notes, and snippets.

View shubhw12's full-sized avatar
🎯
Focusing

Shubham Wagh shubhw12

🎯
Focusing
  • Pune
View GitHub Profile
@shubhw12
shubhw12 / gist:efe11e3fdd5f22efdfe42ef81bf25893
Created February 16, 2021 05:15
Add custom styles to TINY MCE Editor
add_action('admin_enqueue_scripts' , 'custom_editor_styles');
function custom_editor_styles( ){
echo '
<style>
.mce-content-body p{
color:red;
}
</style>
';
@shubhw12
shubhw12 / gist:7f75be0e68a87ff81d05a7f05d10747b
Created February 12, 2021 04:54
Remove cart icon if empty in new header footer builder.
add_action( 'wp', 'remove_empty_cart_icon_from_header' );
function remove_empty_cart_icon_from_header( $show ) {
if ( null != WC()->cart && 0 == WC()->cart->get_cart_contents_count() ) {
remove_action( 'astra_header_woo_cart', array( Astra_Builder_Header::get_instance(), 'header_woo_cart' ) );
}
}
@shubhw12
shubhw12 / gist:9a753c2b60f95898b1e0b9b5ecbf4689
Created October 12, 2020 16:13
Show both last updated and published date in the post meta.
function your_prefix_post_date( $output ) {
$format = apply_filters( 'astra_post_date_format', '' );
$modified_date = esc_html( get_the_modified_date( $format ) );
$modified_on = sprintf(
esc_html( '%s' ),
$modified_date
);
@shubhw12
shubhw12 / gist:a93c2c2bda6d36bb070f7c6c8aeaa97b
Created October 12, 2020 11:37
Show only pages in the search results
add_action( 'wp', 'astra_modify_search_loop', 99 );
/**
* Modify Search Loop.
*
* @return void
*/
function astra_modify_search_loop() {
remove_action( 'astra_content_loop', array( Astra_Loop::get_instance(), 'loop_markup' ) );
add_action( 'astra_content_loop', 'astra_redo_loop_markup' );
@shubhw12
shubhw12 / gist:0960a12fd673830321f015c8d562b052
Last active October 12, 2020 11:36
Show only posts in the search results even if woo commerce is activated
add_action( 'wp', 'astra_modify_search_loop', 99 );
/**
* Modify Search Loop.
*
* @return void
*/
function astra_modify_search_loop() {
remove_action( 'astra_content_loop', array( Astra_Loop::get_instance(), 'loop_markup' ) );
add_action( 'astra_content_loop', 'astra_redo_loop_markup' );
@shubhw12
shubhw12 / gist:fa3d5df0e49799fa66a339ab7db7613b
Created July 22, 2020 07:20
Add back to category button at the end of every single product
add_action ('woocommerce_after_single_product','add_back_product_category_button', 5);
function add_back_product_category_button(){
// Get the product categories set in the product
$terms = wp_get_post_terms( get_the_id(), 'product_cat' );
// Check that there is at leat one product category set for the product
if(sizeof($terms) > 0){
// Get the first product category WP_Term object
$term = reset($terms);
@shubhw12
shubhw12 / gist:f9fdc91c64bc2ee935a2fca4f877a409
Created July 17, 2020 06:42
Astra and Google fonts preload .
add_action( 'wp_head', 'add_astra_fonts_preload', 1 );
function add_astra_fonts_preload() {
$font_list = apply_filters( 'astra_render_fonts', Astra_Fonts::get_fonts() );
$google_fonts = array();
$font_subset = array();
$system_fonts = Astra_Font_Families::get_system_fonts();
foreach ( $font_list as $name => $font ) {
if ( ! empty( $name ) && ! isset( $system_fonts[ $name ] ) ) {
// Add font variants.
$google_fonts[ $name ] = $font['variants'];
add_action( 'astra_woo_single_title_after', 'custom_sub_title', 10 );
function custom_sub_title() {
$data = get_post_meta( get_the_ID() , 'wc_ps_subtitle', true );
if( $data ){
?>
<p class="custom-product-subtitle">
<?php echo $data ?>
</p>
<?php
}
@shubhw12
shubhw12 / gist:d7acc07647bf5924cf60e2472c14b55e
Created June 30, 2020 08:02
custom count in category box on the shop page. ( https://share.getcloudapp.com/jkuQvNkR )
remove_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title', 10 );
add_action( 'woocommerce_shop_loop_subcategory_title', 'custom_category_title', 10 );
function custom_category_title( $category ) {
?>;
<h2 class="woocommerce-loop-category__title">
<?php
if ( $category->count > 0 ) {
echo ' <mark class="count">(' . esc_html( $category->count ) . ')</mark>'; // WPCS: XSS ok.
}
?>
@shubhw12
shubhw12 / gist:8f15f64e97079e901843d1788784f48f
Created June 24, 2020 14:57
Display parent category below individual product if only we are showing only products on the shop page.
add_filter('astra_woo_shop_product_categories' , 'fnc_category');
function fnc_category($args = array()){
$woocommerce_category_id = get_queried_object_id();
$args = array(
'parent' => $woocommerce_category_id
);
$terms = get_terms( 'product_cat', $args );
$categories = array();
if ( $terms ) {