Skip to content

Instantly share code, notes, and snippets.

View santanup789's full-sized avatar

Santanu Patra santanup789

  • Webskitters
  • India
View GitHub Profile
@santanup789
santanup789 / functions.php
Created October 22, 2024 07:44
From Tablepress wordpress plugin get the time of the latest modified table
//With the help of this existing code block inside the plugin https://github.com/TablePress/TablePress/blob/ea2ecc02d3b69925b7322dd195f1a32898b59c38/classes/class-import.php#L375-L382
<?php
function column_table_last_modified() {
$existing_tables = array();
// Load all table IDs and names for a comparison with the file name.
$table_ids = TablePress::$model_table->load_all( false );
foreach ( $table_ids as $table_id ) {
// Load table, without table data, options, and visibility settings.
$table = TablePress::$model_table->load( $table_id, false, false );
@santanup789
santanup789 / functions.php
Created October 19, 2023 05:21
Add extra registration form fields in woocommerce registration form along with adding profile picture uploading option
<?php
function wooc_extra_register_fields() {?>
<p class="form-row form-row-first">
<label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>
@santanup789
santanup789 / custom.js
Created July 14, 2023 13:26
Step form auto trigger next in Gravity form
<script>
jQuery(function($){
$( document ).on( 'elementor/popup/show', (event, id, instance) => {
if ( id === 2063 ) {
setTimeout(function(){
if($('#elementor-popup-modal-'+id+' .gform_wrapper').length){
var formID = $('#elementor-popup-modal-'+id+' .gform_wrapper form').attr('data-formid');
console.log('gfrom found');
$('form[id^="gform_'+formID+'"]').on('change', function (e) {
var getCurrentPage = $('#gform_source_page_number_'+formID+'').val();
@santanup789
santanup789 / functions.php
Created March 9, 2023 07:31
Create a new column in cutom taxonomy term table and display the term ID
<?php
//Creating a new column in Experience term table to show term ID
add_filter( 'manage_edit-experience_columns', 'wpdocs_add_new_genre_columns' );
add_filter( 'manage_edit-destination_columns', 'wpdocs_add_new_genre_columns' );
function wpdocs_add_new_genre_columns( $columns ) {
$columns['catID'] = __( 'Term ID' );
return $columns;
}
@santanup789
santanup789 / functions.php
Created July 28, 2022 07:07
Render Read only and Disable option for any ACF
//Just repeat this add_action hook available for the ACF plugin
//add_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field');
//for the other types of fields be just changing the value of the type in the hook "/type=text".
//e.g. add_action('acf/render_field_settings/type=textarea', 'add_readonly_and_disabled_to_text_field');
//It will add 2 radio option read-only and disable the field for the textarea field.
<?php
add_action('acf/render_field_settings/type=textarea', 'add_readonly_and_disabled_to_text_field');
add_action('acf/render_field_settings/type=text', 'add_readonly_and_disabled_to_text_field');
@santanup789
santanup789 / functions.php
Created July 28, 2022 07:04
Capture post view by capturing IP address using WordPress Function and ACF field [meta field]. Help full for creating any section for Popular Posts.
//Create 2 custom meta field with the names: 'wpb_post_views_count' and 'user_ip'.
<?php
function wpb_set_post_views($postID) {
$user_ip = $_SERVER['REMOTE_ADDR']; //retrieve the current IP address of the visitor
$key = $user_ip . 'x' . $postID; //combine post ID & IP to form unique key
$value = array($user_ip, $postID); // store post ID & IP as separate values (see note)
$visited = get_transient($key); //get transient and store in variable
//check to see if the Post ID/IP ($key) address is currently stored as a transient
if ( false === ( $visited ) ) {
@santanup789
santanup789 / functions.php
Created February 22, 2022 14:09
Display the published date 2days prior when publishing the post on the front end to show the 2days prior date
<!-- We will not do anything to change the detfault publishe date -->
<!-- We will use the publishe date to create a date 2days prior of the publishe date using a custom date time field. -->
<!-- Create a date-time custom field using ACF plugin for your CPT or any kind of post type -->
<!-- Use this function in your theme's functions.php and use the custom field's meta name to fire the update query -->
<!-- Also you can change the prior day or post day by just changing "-1 day or +1 day" inside this function -->
<?php
add_action( 'acf/save_post', 'my_acf_save_post' );
function my_acf_save_post( $post_id ) {
//$date = get_the_date( 'Y-m-d H:i:s', $post_id );
@santanup789
santanup789 / googlemap.php
Last active January 14, 2022 14:19
Google map multiple marker with clickable location list which makes the marker pointer centar to the map after click. With marker binding feature. [WordPress ACF repeater fields for locations required.]
<?php
?>
<script src="https://maps.googleapis.com/maps/api/js?key=<?php the_field('gmap_api_key', 'option'); ?>"></script>
<style>
.acf-map { height: 400px; }
p.emails a:not(:last-child)::after {
content: ', ';
}
</style>
<?php if( have_rows('address', 'option') ): ?>
@santanup789
santanup789 / functions.php
Created January 5, 2022 10:59
Re arrange or add WooCommer product ratings with number of reviews before shop loop item title using woocommerce hook
<?php
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );// remoove default star rating from shop listing page
//add star rating before shop loop title
add_filter( 'woocommerce_before_shop_loop_item_title', 'star_rating' );
function star_rating() {
global $product;
if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) {
return;
@santanup789
santanup789 / functions.php
Last active January 5, 2022 10:57
Add woocommerce product categories after shop loop item title using woocommerce hook
<?php
//add Product category and number of flavour attribute after shop loop title
add_filter( 'woocommerce_after_shop_loop_item_title', 'so58344618_variation_count' );
function so58344618_variation_count() {
global $product;
$categories = get_the_terms( $post->ID, 'product_cat' );
$catList = '';
foreach($categories as $category) {
if(!empty($catList)) {