Skip to content

Instantly share code, notes, and snippets.

function woocommerce_detect_coupon_code() {
// Check if custom URI with coupon URL is requested
if(!empty($_GET['code'])) {
// Check if cart/shop page is set & redirect to it
// $shop_page_id = wc_get_page_id('shop');
// $cart_page_id = wc_get_page_id('cart');
if(!empty($cart_page_id) && WC()->cart->get_cart_contents_count() > 0) {
// $redirect_page = $cart_page_id;
function matterhorn_insert_product($product_data){
$post_id = wp_insert_post( array(
'post_author' => 1,
'post_title' => $product_data['mh_name'],
'post_content' => $product_data['mh_desc'],
'post_status' => 'publish',
'post_type' => "product",
) );
wp_set_object_terms( $post_id, 'variable', 'product_type' );
@xlawok
xlawok / Wordpress pods change order and header of pods fields
Created June 7, 2020 13:47
Wodpress change order and header of pods fields
add_action('pods_meta_groups', 'customize_frontpage',10,2);
function customize_frontpage($type, $name){
global $post_ID, $post_type;
if ( empty ( $post_ID ) or 'page' !== $post_type )
return;
if ( $post_ID === (int) get_option( 'page_on_front' ) ){
//change order and header of pods fields
@xlawok
xlawok / PODS repeater - get in reapeater loop relationship field ID
Last active June 9, 2020 15:06
Wordpress PODS repeater and realationship - how to get in reapeater loop relationship field ID
$top_banner_items=pods_field( 'front_page_banner ', get_the_ID());
foreach($top_banner_items as $item):
$query = "SELECT related_item_id FROM {$wpdb->prefix}podsrel where item_id={$item['id']} and field_id=153";
$img_srcset = wp_get_attachment_image_srcset( $item['zdjcie'],'large');
echo '<a href="'.get_category_link($wpdb->get_var($query)).'" title="'.get_the_title().'" class="product-image">';
echo "<img class=''
sizes='(max-width: 991px) 100vw, 40vw'
@xlawok
xlawok / wp custom menu intems style
Created June 17, 2020 16:28
Wordpress add custom styles to menu nav (with carbon fields)
// Adding a custom color and weight to the links
add_filter('nav_menu_link_attributes', 'crb_nav_menu_link_attributes', 10, 4);
function crb_nav_menu_link_attributes($atts, $item, $args, $depth) {
$crb_color = carbon_get_nav_menu_item_meta($item->ID, 'nav_color');
$crb_weight = carbon_get_nav_menu_item_meta($item->ID, 'nev_weight');
$crb_color = ! empty( $crb_color ) ? ' color: ' . $crb_color . '; ' : '';
$crb_weight = ! empty( $crb_weight ) ? ' font-weight: ' . $crb_weight . '; ' : '';
$atts['style'] = $crb_color.$crb_weight;
@xlawok
xlawok / woo custom badge on image
Last active June 17, 2020 16:29
woocommerce add custom badge on image (based on tag/category) of related products
// ADD NOWOŚĆ TAG ONA ZDJĘCIE PRODUKTÓW POWIĄZANYCH
add_action('woocommerce_before_shop_loop_item_title','show_novelty_on_related_products',11);
function show_novelty_on_related_products(){
global $product;
if(is_product()){
if( has_term( array( 'Nowości' ), 'product_tag' ,$product) ) {
echo '<span class="novelty">Nowość!</span>';
}
}
@xlawok
xlawok / woo REARRANGE PRODUCT IN NOWOŚCI TAG
Created June 17, 2020 16:30
woocommerce change order achive PRODUCT based on tag possible category also
//REARRANGE PRODUCT IN NOWOŚCI TAG
add_filter('woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby');
function custom_default_catalog_orderby($sort_by) {
if( !is_tax( 'product_tag', 'Nowości' ) ) {
return $sort_by;
}
return 'date'; // Can also use title and price
}
@xlawok
xlawok / woocommerce paragon lub faktura
Created June 17, 2020 16:34
woocommerce add receipt of invoice to checkout, with validation and display it in wp-admin
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// ADD NIP AND REARRANGE
function custom_override_checkout_fields( $fields ) {
$fields['billing']['pk_nip'] = array(
'label' => __('NIP', 'woocommerce'),
'placeholder' => _x('Wpisz NIP, jeżeli chcesz otrzymać fakturę', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true,
@xlawok
xlawok / WP instagram carousel slider (instagram 10 web plugin + js tiny slider)
Created June 20, 2020 10:10
Create carousel slider of instagram feed with wp plugin "Instagram Feed by 10Web" and JS "tiny slider".
@xlawok
xlawok / gist:26a5abb3703bc6a6af7c69ded0537845
Created October 7, 2020 13:13
Remove canonical tag in sole WP and in Yoast
remove_action('wp_head', 'rel_canonical');
add_action('init', function() {
add_filter( 'wpseo_canonical', '__return_false', 10 );
});