Skip to content

Instantly share code, notes, and snippets.

View marcosnakamine's full-sized avatar

Marcos Nakamine marcosnakamine

View GitHub Profile
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:04
WooCommerce - Get product categories, image and permalink
<?php
$cat = get_categories( array(
'taxonomy' => 'product_cat'
) );
foreach( $cat as $key => $value ){
echo $value->name;
echo wp_get_attachment_url( get_term_meta( $value->term_id, 'thumbnail_id', true ) );
echo get_term_link( $value->term_id, 'product_cat' );
var_dump( $value );
}
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:03
WordPress - Show user info if logged in
<?php
if( is_user_logged_in() ) {
$user = wp_get_current_user();
echo $user->display_name;
}
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:04
WooCommerce - Get src of galery
<?php
$product = wc_get_product( get_the_ID() );
$gallery = $product->get_gallery_attachment_ids();
foreach ( $gallery as $key => $value ) {
$img = wp_get_attachment_image_src( $value, 'full' );
echo $img[0];
}
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:03
WordPress - Conditional tags
<?php
var_dump('is_shop '.is_shop());
var_dump('is_product '.is_product());
var_dump('is_single '.is_single());
var_dump('is_archive '.is_archive());
var_dump('is_page '.is_page());
var_dump('is_product_category '.is_product_category());
var_dump('is_woocommerce '.is_woocommerce());
@marcosnakamine
marcosnakamine / functions.php
Last active April 22, 2024 13:52
WooCommerce - Add new rule to ACF
<?php
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
$choices['Woocommerce']['woocommerce_attribute'] = 'Atributo';
return $choices;
}
add_filter('acf/location/rule_values/woocommerce_attribute', 'acf_location_rules_values_woocommerce_attribute');
function acf_location_rules_values_woocommerce_attribute( $choices ) {
$atributes = wc_get_attribute_taxonomies();
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:04
WooCommerce - Get product info
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<style>
img {max-width:100%; }
</style>
</head>
<body>
@marcosnakamine
marcosnakamine / 000-default.conf
Last active January 24, 2017 16:24
Apache 2.4 - Localhost configuration
#/etc/apache2/sites-available/000-default.conf
DocumentRoot /home/user/Projects
<Directory /home/user/Projects/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
@marcosnakamine
marcosnakamine / index.php
Last active March 21, 2017 20:02
WordPress - Get src of post galery
<?php
$aFotos = get_post_gallery(get_the_ID(), false);
$aFotosId = explode(',',$aFotos['ids']);
$aFotos = $aFotos['src'];
foreach ($aFotosId as $key => $value) {
echo $aFotos[$key];
}
@marcosnakamine
marcosnakamine / date.php
Created November 27, 2016 16:35
PHP - Compare two dates
<?php
if(strtotime(date('d-m-Y')) > strtotime('27-11-2016')) {
echo 'OK';
}
@marcosnakamine
marcosnakamine / script.js
Created November 25, 2016 23:36
Fancybox - Trigger open image
$.fancybox.open({
href:'image.jpg'
});