Skip to content

Instantly share code, notes, and snippets.

View binzorellino's full-sized avatar

Imre T. B. binzorellino

View GitHub Profile
@rmpel
rmpel / translate-custom-post-type-archive-slug.php
Last active October 30, 2023 08:39
Translate post-type-archive-slug when different from post-type-slug. WPML allows translating custom post-type slug, but not the custom post-type-archive slug
<?php
/**
* Translate post-type-archive-slug when different from post-type-slug.
*
* You can have your archive slug set to, for example /books and the singles on /book/title by setting
* $args['rewrite'] => [ 'slug' => 'book', ... ];
* $args['has_archive'] => 'books';
* when registering your post_type
*
function equalHeight(element) {
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(element).each(function() {
$el = $(this);
@abelcallejo
abelcallejo / README.md
Last active August 16, 2023 08:25
PHP date manipulation techniques

PHP date manipulation techniques

php

ISO string date to PHP date object

<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
@erichuang2015
erichuang2015 / wc_ajax_add_to_cart.php
Created October 14, 2018 00:58
Woocommerce Ajax Add To Cart Button
<?php
//AJAX ADD TO CART BUTTON
$product_id = 143;
if( !my_custom_cart_contains( $product_id ) ) {
?>
<button class="my-custom-add-to-cart-button" data-product-id="<?php echo $product_id; ?>">add to cart</button>
<?php
} else {
?>
@aslamdoctor
aslamdoctor / woocommerce-popular-products.php
Last active November 20, 2022 06:24
Woocommerce : Get popular products using wp_query
@betojsx
betojsx / custom-post-type-in-author-archive
Last active July 14, 2022 15:46
Display Custom Post Type in Author Archive WordPress
// In functions.php, add:
<?php
function post_types_author_archives($query) {
if ($query->is_author)
// Add 'books' CPT and the default 'posts' to display in author's archive
$query->set( 'post_type', array('books', 'posts') );
remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
@nickbudi
nickbudi / README.md
Last active November 4, 2023 10:53
Cygwin git compatibility with VS Code (or other Windows programs) using cygpath

Cygwin Git + VS Code compatibility

Thanks and credit to mattn and ferreus on GitHub.

Also check out Developing on WSL and/or wslpath (Windows 10 Build 17046 or later) if you're using the Windows Subsystem for Linux.

@guydumais
guydumais / functions.php
Last active April 30, 2020 07:07
WordPress ➧ Disable jQuery Migrate in WordPress
<?php
/**
* Disable jQuery Migrate in WordPress.
*
* @author Guy Dumais.
* @link https://en.guydumais.digital/disable-jquery-migrate-in-wordpress/
*/
add_filter( 'wp_default_scripts', $af = static function( &$scripts) {
if(!is_admin()) {
$scripts->remove( 'jquery');
@monecchi
monecchi / wc-customer-orders-number.php
Last active September 18, 2023 13:40
WooCommerce Customer's Orders Total - Sum of all the current month's orders made by a customer
/*********************************************************************************************/
/** Get the total sum (money spent) of orders made by a user with a "complete" status in WooCommerce. This will output the current month's sum of all orders made by the customer. **/
/*********************************************************************************************/
<?php
function current_customer_month_count( $user_id=null ) {
if ( empty($user_id) ){
$user_id = get_current_user_id();
}