Skip to content

Instantly share code, notes, and snippets.

View marcosnakamine's full-sized avatar

Marcos Nakamine marcosnakamine

View GitHub Profile
@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 / class.ys_mail.php
Last active November 18, 2023 06:57
WordPress - Send mail wp_mail with attachment
<?php
class YS_Mail {
public function YS_Mail() {}
public function enviar( $e ) {
$headers = "From: ".$e['from_name']." <".$e['to_mail']."> \n";
$headers .= "Reply-To:".$e['from_name']." <".$e['from_mail']."> \n";
@marcosnakamine
marcosnakamine / example_feed_xml_rss.xml
Created March 22, 2017 20:20
Google Merchant - Feed example in xml
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>Example - Online Store</title>
<link>http://www.example.com</link>
<description>
This is a sample feed containing the required and recommended attributes for a variety of different products
</description>
<!--
First example shows what attributes are required and recommended for items that are not in the apparel category
@marcosnakamine
marcosnakamine / index.php
Created April 10, 2017 18:21
PHP - Google Invisible reCAPTCHA example
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
document.getElementById("demo-form").submit();
}
</script>
</head>
@marcosnakamine
marcosnakamine / woocommerce.php
Last active October 25, 2020 17:21
WooCommerce - Get variable product attributes
<?php $attributes = $product->get_attributes() // GET ALL ATRIBUTES ?>
<?php foreach( $attributes as $key => $value ): ?>
<?php $attribute_name = preg_replace( '/pa_/', '', $key ) // GET ATTRIBUTE NAME ?>
<label>
<select name="attribute_pa_<?php echo $attribute_name ?>" id="attribute_pa_<?php echo $attribute_name ?>">
<option value=""><?php echo $attribute_name ?></option>
<?php $attribute_name = wc_get_product_terms( get_the_ID(), $key ) // GET ATTRIBUTE NAME ?>
<?php $attribute_slug = wc_get_product_terms( get_the_ID(), $key, array( 'fields' => 'slugs' ) ) // GET ATTRIBUTE SLUG ?>
<?php for ( $i=0; $i<count( $attribute_name ); $i++ ): // array_slice BECAUSE ARRAY INDEX IS NOT SEQUENCIAL ?>
<option value="<?php $slug = array_slice( $attribute_slug, $i, 1 ); echo $slug[0]; ?>"><?php $name = array_slice( $attribute_name, $i, 1 ); echo $name[0]; ?></option>
@marcosnakamine
marcosnakamine / wc-skeleton-shipping-method-example.php
Created July 24, 2020 14:04 — forked from woogists/wc-skeleton-shipping-method-example.php
[Shipping Method API] WooCommerce skeleton shipping method plugin code example.
<?php
/*
Plugin Name: Your Shipping plugin
Plugin URI: https://woocommerce.com/
Description: Your shipping method plugin
Version: 1.0.0
Author: WooThemes
Author URI: https://woocommerce.com/
*/
@marcosnakamine
marcosnakamine / script.js
Created October 24, 2017 13:28
jQuery - WP Smush auto click
setInterval(function(){
botao = jQuery('#wp-smush-bulk-wrap-box > div.box-container > div.wp-smush-bulk-wrapper > button');
if( botao.attr('disabled') != 'disabled' ) {
botao.trigger('click');
}
}, 1000);
@marcosnakamine
marcosnakamine / .htaccess
Created August 13, 2019 15:13
WordPress - Protect uploads folder when not logged
RewriteEngine On
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule ^.*/uploads/.*$ http://domain.com/protected.jpg [L,R=301]
namespace: "flex-", //{NEW} String: Prefix string attached to the class of every element generated by the plugin
selector: ".slides > li", //{NEW} Selector: Must match a simple pattern. '{container} > {slide}' -- Ignore pattern at your own peril
animation: "fade", //String: Select your animation type, "fade" or "slide"
easing: "swing", //{NEW} String: Determines the easing method used in jQuery transitions. jQuery easing plugin is supported!
direction: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical"
reverse: false, //{NEW} Boolean: Reverse the animation direction
animationLoop: true, //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
smoothHeight: false, //{NEW} Boolean: Allow height of the slider to animate smoothly in horizontal mode
startAt: 0, //Integer: The slide that the slider should start on. Array nota
@marcosnakamine
marcosnakamine / function.php
Created January 30, 2018 17:28
WordPress - Change language programmatically via url
<?php
function wpsx_redefine_locale( $locale ) {
$lang = $_GET['lang'];
if( $lang == 'en'){
$locale = 'en_US';
} else {
$locale = 'pt_BR';
}
return $locale;
}