Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Updating knowledgebase...

Luis CasperBraske

🤓
Updating knowledgebase...
View GitHub Profile
@CasperBraske
CasperBraske / functions.php
Created Aug 30, 2021
[WCBR] Resposta post WooCommerce Brasil - 4342857705782162
View functions.php
<?php
function wcbr_create_lottery_numbers( $order_id ){
$order = wc_get_order( $order_id );
$items = $order->get_items();
$lucky_product_id = 28;
foreach( $items as $item_id => $item ) {
@CasperBraske
CasperBraske / functions.php
Created Aug 19, 2021
Desabilitar ME por produto no Dokan
View functions.php
<?php
function arti_mpme_custom_disable_me_shipping_field(){
global $post;
$me_disabled = get_post_meta( $post->ID, '_me_product_disabled', true );
?>
<div class="dokan-form-group">
<input id="_me_product_disabled" name="_me_product_disabled" value="yes" type="checkbox"<?php checked( $me_disabled, 'yes' ); ?>>
@CasperBraske
CasperBraske / functions.php
Created Aug 18, 2021
Permitir que etiquetas sejam geradas e status customizados.
View functions.php
<?php
// Adicionar status permitido para gerar etiquetas.
add_filter( 'arti_me_labels_generation_allowed_statuses', function( $statuses ){
$statuses[] = 'id_do_seu_status';
// $statuses[] = 'id_de_outro_status';
return $statuses;
@CasperBraske
CasperBraske / Cotação retornada pela API.php
Last active Nov 10, 2021
Scripts para testar os métodos no carrinho
View Cotação retornada pela API.php
<?php
add_action( 'arti_me_shipping_debug', function( $debug_message, $raw_message ){
if( is_array( $raw_message ) ) {
arti_mpme_show_messages_in_cart( array_column( $raw_message, 'custom_price', 'name' ) );
}
}, 10, 2 );
@CasperBraske
CasperBraske / functions.php
Created Jun 9, 2021
Exibir campo de CPF nos pedidos do WCFM no painel do vendedor
View functions.php
<?php
add_action( 'wcfm_order_details_after_shipping_address', function( $order ){
$cpf = $order->get_meta( '_billing_cpf' );
?>
<div><strong>CPF:</strong> <?php echo esc_html( $cpf ); ?></div>
<?php
} );
@CasperBraske
CasperBraske / functions.php
Last active Apr 23, 2021
Exibir dados do Extra Checkout Fields/Brazilian Market na página de pedido do Dokan
View functions.php
<?php
add_filter( 'woocommerce_order_formatted_shipping_address', function( $address, $order ){
if( $parent_order_id = $order->get_parent_id() ){
$order = wc_get_order( $parent_order_id );
}
$address['number'] = $order->get_meta( '_shipping_number' );
$address['neighborhood'] = $order->get_meta( '_shipping_neighborhood' );
@CasperBraske
CasperBraske / functions.php
Created Apr 1, 2021
[WooCommerce] Moving cart calculator to the top of the cart collaterals
View functions.php
<?php
/**
* Moving cart calculator to the top of the cart collaterals
*/
add_filter( 'woocommerce_shipping_show_shipping_calculator', '__return_false' );
add_action( 'woocommerce_cart_totals_before_shipping', function(){
$packages = WC()->shipping()->get_packages();
$first_package = array_shift( $packages );
$formatted_destination = WC()->countries->get_formatted_address( $first_package['destination'], ', ' );
@CasperBraske
CasperBraske / functions.php
Created Mar 29, 2021
Fix broken Query Monintor in WC Marketplace seller panel
View functions.php
<?php
add_action( 'wp_enqueue_scripts', function(){
wp_enqueue_style(
'query-monitor',
QueryMonitor::init()->plugin_url( "assets/query-monitor.css" ),
[],
QueryMonitor::init()->plugin_ver( "assets/query-monitor.css" )
);
}, PHP_INT_MAX );
@CasperBraske
CasperBraske / Referência de filtros Marketplace-Melhor Envio.md
Last active Mar 25, 2021
Referência de filtros Marketplace/Melhor Envio
View Referência de filtros Marketplace-Melhor Envio.md

Utilidades

add_filter( 'arti_mpme_show_messages_in_cart', '__return_true' );

Mostra mensagens de debug ("depuração") no carrinho para usuários administradores rereferentes ao cálculo do frete, como erros de configuração do vendedor e mensagens de retorno da API.

add_filter( 'arti_me_force_agency_list_update', '__return_true' );
@CasperBraske
CasperBraske / functions.php
Created Feb 26, 2021
[Dokan] Add support to multiple postcode ranges.
View functions.php
<?php
use WeDevs\DokanPro\Shipping\ShippingZone;
add_filter( 'dokan_vendor_shipping_is_available', function( $is_available, $package, $shipping ){
$seller_id = $package['seller_id'];
$destination_postcode = isset( $package['destination']['postcode'] ) ? $package['destination']['postcode'] : '';
$destination_postcode = wc_normalize_postcode( $destination_postcode );
if ( empty( $seller_id ) ) {