Skip to content

Instantly share code, notes, and snippets.

@xlawok
xlawok / wp add class to wp_list_categories
Created December 1, 2020 10:20
Wordpress add class to category wp_list_categories
// add class to wp_list_categories
// if category has a children add cat-parent class
add_filter( 'category_css_class', 'add_class_to_category', 10, 4);
function add_class_to_category($css_classes, $category, $depth, $args) {
$children = get_terms( $category->taxonomy, array(
'parent' => $category->term_id,
'hide_empty' => false
) );
// print_r($children); // uncomment to examine for debugging
@xlawok
xlawok / WP change srcset sizes max-width thumbnails
Created December 1, 2020 10:31
WP change srcset sizes max-width for archive thumbnails images
add_filter( 'wp_calculate_image_sizes', 'pk_content_archive_thumbnail_image_sizes', 10, 5 );
/**
* Change the default "sizes" attribute created by WordPress
* for the content archive thumbnails
*/
function pk_content_archive_thumbnail_image_sizes( $sizes, $size, $image_src, $image_meta, $attachment_id ) {
if( is_archive() && is_main_query() || is_home() ) {
$sizes = '(max-width: 600px) 100vw, 50vw';
}
@xlawok
xlawok / Woo + carbonfields - shipment modyfication - weight and country
Created December 7, 2020 14:21
Woo shipment modyfication - based on weight and country, with on Carbon Fields on board
add_filter( 'woocommerce_package_rates', 'pk_woocommerce_shipping_by_weight', 9999, 2 );
function pk_woocommerce_shipping_by_weight( $rates, $package ) {
$destination = $package['destination'];
$country = $destination['country'];
//cost sets in carbonfields for each reagions
$pl_shipping_costs = carbon_get_theme_option( 'pk_shipping_costs_pl' );
$inter_shipping_costs = carbon_get_theme_option( 'pk_shipping_costs_inter' );
$cart_weight=WC()->cart->get_cart_contents_weight();
@xlawok
xlawok / functions.php
Created December 19, 2020 21:48
Carbon fields undefined core.min.js not visible carbon fields in admin area.
<?php
// probably there is a problem with directory to carbonfield plugin.
// As it is shown under this url https://github.com/htmlburger/carbon-fields/issues/457
// this problem appears when plugin is in symlinked directory.
// add below line to function.php
define('Carbon_Fields\URL', WP_PLUGIN_URL. '/carbon-fields/vendor/htmlburger/carbon-fields');
@xlawok
xlawok / functions.php
Last active December 19, 2020 21:49
Woo + carbonfields - shipment modyfication - weight, zones and country, and class
//carbonfields settings:
function pk_get_shipping_countries(){
//get shipping countries for defining countries for bulky products
$woo_countries = new WC_Countries();
$countries = $woo_countries->get_allowed_countries();
return $countries;
}
function pk_get_shipping_zones(){
@xlawok
xlawok / carbonfields.php
Created January 8, 2021 14:23
Wordpress - Carbon fields + contact form 7 list all forms
<?php
// define( 'Carbon_Fields\URL', get_parent_theme_file_path( 'vendor/htmlburger/carbon-fields' ) );
// \Carbon_Fields\Carbon_Fields::boot();
define('Carbon_Fields\URL', WP_PLUGIN_URL. '/carbon-fields/vendor/htmlburger/carbon-fields');
use Carbon_Fields\Container;
use Carbon_Fields\Field;
function sc_get_contact_forms7(){
@xlawok
xlawok / header.php
Created May 10, 2021 18:44
Woocommerce paged category and tags canonical
<?php
if(is_paged()&&is_product_category()) {
$thisCat = get_query_var('product_cat');
$category_link = get_term_link($thisCat, 'product_cat');
echo '<link rel="canonical" href="' . $category_link . '" />';
}
if(is_paged()&&is_product_tag()) {
$thisTag = get_query_var('product_tag');
@xlawok
xlawok / ProductListingFrontController.php
Created July 18, 2021 21:37
Prestashop 1.7 custom pagination for certain categories
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
@xlawok
xlawok / WP SEO YOAST and ALL IN ONE
Last active July 19, 2021 21:40
WP SEO YOAST and ALL IN ONE
/ALL IN ONE title
add_filter( 'aioseop_title', 'change_wordpress_seo_title' );
function change_wordpress_seo_title( $title ){
$term = get_queried_object();
if(!empty($term)&&$term->taxonomy=='category'){
if($term->term_id==62) $title="Artykuły BHP Wrocław - Hurtownia Online ".get_bloginfo( 'name' );
}
return $title;
@xlawok
xlawok / head.tpl
Last active July 20, 2021 12:18
Prestashop title and canonical
{assign var="aw_url" value=$smarty.server.REQUEST_URI}
{if strpos($aw_url,'?') !== false}
<meta name="robots" content="noindex, follow">
{elseif $page.meta.robots !== 'index'}
<meta name="robots" content="{$page.meta.robots}">
{/if}
{if $page.page_name=="category"}