Skip to content

Instantly share code, notes, and snippets.

View kreamweb's full-sized avatar

Emanuela Antonina Castorina kreamweb

  • Kream di Emanuela Castorina
  • Acicatena (CT) - Italy
View GitHub Profile
@kreamweb
kreamweb / functions.php
Last active February 21, 2024 10:17
woocommerce-shipping-filter
<?php
/* this function remove free shipping if the discount of dynamic is applied in the cart */
if( class_exists('YITH_WC_Dynamic_Discounts') ){
add_filter( 'woocommerce_shipping_packages', 'show_packages' );
function show_packages($packages){
$label = YITH_WC_Dynamic_Discounts()->label_coupon;
$newpack = $packages;
foreach ( $packages as $key_package => $package ) {
if( isset( $package['applied_coupons'] ) && in_array( $label, $package['applied_coupons'] ) ){
if ( sizeof( $package['rates'] ) > 0 ) {
@kreamweb
kreamweb / code.txt
Created February 4, 2016 06:48
YITH WooCommerce Ajax Search Shortcode
To show the search form,
you can use
[yith_woocommerce_ajax_search]
or php code:
<?php echo do_shortcode('[yith_woocommerce_ajax_search]​'); ?>
@kreamweb
kreamweb / functions.php
Last active May 16, 2023 20:35
**YITH Point of Sale for WooCommerce** Hide cash in hand to cashiers
<?php
if ( defined( 'YITH_POS_VERSION' ) && ! function_exists( 'yith_pos_add_user_role_to_pos_class' ) ) {
add_filter( 'yith_pos_body_classes', 'yith_pos_add_user_role_to_pos_class' );
function yith_pos_add_user_role_to_pos_class( $body_class ) {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$body_class = array_merge( $body_class, (array) $user->roles );
}
<?php
add_action( 'admin_enqueue_scripts', 'ywpi_pdf_template_licence_key', 99 );
if ( ! function_exists( 'ywpi_pdf_template_licence_key' ) ) {
function ywpi_pdf_template_licence_key() {
$js = "wp.hooks.addFilter('ywpi_pdf_template_demo', 'yith-woocommerce-pdf-invoice/customization', (key) => {
return 'ywpi_live_demo';
} );";
wp_add_inline_script( 'ywpi-pdf-template-builder-script', $js, 'after' );
<?php
add_action( 'admin_enqueue_scripts', 'ywpi_pdf_template_licence_key', 99 );
if ( ! function_exists( 'ywpi_pdf_template_licence_key' ) ) {
function ywpi_pdf_template_licence_key() {
$js = "wp.hooks.addFilter('ywpi_pdf_template_demo', 'yith-woocommerce-pdf-invoice/customization', (key) => {
return 'ywpi_live_demo';
} );";
wp_add_inline_script( 'ywpi-pdf-template-builder-script', $js, 'after' );
@kreamweb
kreamweb / sort-cart-items-by-price.php
Last active September 12, 2022 22:31
Woocommerce - Sort cart items by price
add_action( 'woocommerce_cart_loaded_from_session', 'wpm_cart_order_items_by_price' );
function wpm_cart_order_items_by_price( $cart ) {
//if the cart is empty do nothing
if ( empty( $cart->cart_contents ) ) {
return;
}
//this is an array to collect cart items
import apiFetch from '@wordpress/api-fetch';
import {addQueryArgs} from '@wordpress/url';
import {getCurrentPost} = wp.data.select('core/editor');
const api_path = '/wp/v2/pdf_template/'; //this is the slug of rest_endpoint set inside the register_post_type
function TemplateList() {
function handleOnClick(template) {
@kreamweb
kreamweb / js
Created January 25, 2022 13:55
wp.domReady(() => {
find blocks styles
wp.blocks.getBlockTypes().forEach((block) => {
console.log(block);
if (_.isArray(block['styles'])) {
console.log(block.name, _.pluck(block['styles'], 'name'));
}
});
<?php
if ( function_exists( 'YITH_WC_Subscription_Frontend' ) ) {
add_filter( 'woocommerce_customer_get_downloadable_products', 'woocommerce_order_get_downloadable_items_ywsbs_helper' );
function woocommerce_order_get_downloadable_items_ywsbs_helper( $downloads ) {
if ( ! is_account_page() ) {
return $downloads;
}
<?php
if( defined('YITH_YWRAQ_PREMIUM') ){
add_action('wp_footer','raq_script',9999);
function raq_script() { ?>
<script>
jQuery(document).ready(function($) {