Categoría: Sin categoría

Scripts Varios para WordPress

<?php $loop = new WP_Query( array( 'post_type' => 'NAME_OF_THE_POST_TYPE', 'posts_per_page' => 100 ) ); ?>
<ul>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <?php the_title( '<li><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></li>' ); ?>

<?php endwhile; ?>
</ul>
<?php $loop = new WP_Query( array( 'post_type' => 'product', 'posts_per_page' => 100 ) ); ?>
<ul>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <?php the_title( '<li><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></li>' ); ?>

<?php endwhile; ?>
</ul>

How To Allow Users To Remove Products On Checkout Page in WooCommerce

/**
 * Allows to remove products in checkout page.
 * 
 * @param string $product_name 
 * @param array $cart_item 
 * @param string $cart_item_key 
 * @return string
 */
function lionplugins_woocommerce_checkout_remove_item( $product_name, $cart_item, $cart_item_key ) {
	if ( is_checkout() ) {
		$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
		$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );

		$remove_link = apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
			'<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>',
			esc_url( WC()->cart->get_remove_url( $cart_item_key ) ),
			__( 'Remove this item', 'woocommerce' ),
			esc_attr( $product_id ),
			esc_attr( $_product->get_sku() )
        ), $cart_item_key );

		return '<span>' . $remove_link . '</span> <span>' . $product_name . '</span>';
	}

	return $product_name;
}
add_filter( 'woocommerce_cart_item_name', 'lionplugins_woocommerce_checkout_remove_item', 10, 3 );

Fuente: https://lionplugins.com/blog/remove-products-checkout-page/

Desinstalar y remover datos Woocommerce

How to Uninstall and completely remove WooCommerce

  1. Open your WordPress install’s wp-config.php file
  2. Right before where it says “* That’s all, stop editing! Happy blogging. */” insert a new line, and add the following code define ('WC_REMOVE_ALL_DATA', true); – then save your file;
  3. Deactivate WooCommerce at WP-admin > plugins
  4. Delete WooCommerce at WP-admin > plugins
  5. That’s it!

define('WC_REMOVE_ALL_DATA', true);
https://silicondales.com/tutorials/woocommerce/uninstall-completely-remove-woocommerce/

Eliminar comentario litespeed cache

define( 'LSCACHE_ESI_SILENCE', true );

Trozos de código útiles para ACF

Número total de repeater:
Ej: si tengo 4 repeaters, obtengo el número 4

echo count( get_field('repeater_field') );

Numeración por cada repeater:
Ej: si tengo 4 repeaters, obtengo: 1 2 3 4

<?php
$i = 1;
while(has_sub_field('repeater_field')):
?>

<?php echo $i; ?>

<?php
$i++;
endwhile;
?>

Fuente: https://support.advancedcustomfields.com/forums/topic/how-to-display-the-number-of-the-row-of-the-repeater-field/

Override templates de plugins (Woocommerce) con Oxygen Builder

Debido a Oxygen deshabilita los theme de WordPress, no es posible personalizar los templates de plugin como Woocommerce.

La solución es la siguiente paso por agregar un plugin personalizado con filter hooks.

  1. Primero se debe crear un plugin, acá un ejemplo: https://github.com/srikat/my-custom-functionality
    Nombre ejemplo del plugin: my-custom-functionality
  2. Copiar archivos de los templates del plugin a override, ejemplo de Woocommerce: MIDOMINIO.COM/wp-content/plugins/woocommerce/templates
  3. Pegar en: MIDOMINIO.COM/wp-content/plugins/my-custom-functionality/woocommerce/
  4. Agregar el siguiente código en el archivo MIDOMINIO.COM/wp-content/plugins/my-custom-functionality/plugin.php
add_filter( 'woocommerce_locate_template', 'intercept_wc_template', 10, 3 );
/**
 * Filter the cart template path to use cart.php in this plugin instead of the one in WooCommerce.
 *
 * @param string $template      Default template file path.
 * @param string $template_name Template file slug.
 * @param string $template_path Template file name.
 *
 * @return string The new Template file path.
 */
function intercept_wc_template( $template, $template_name, $template_path ) {

	$template_directory = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'woocommerce/';
	$path = $template_directory . $template_name;

	return file_exists( $path ) ? $path : $template;

}

Opción overriding un archivo específico (ejemplo: cart.php) Woocommerce:

add_filter( 'woocommerce_locate_template', 'intercept_wc_template', 10, 3 );
/**
 * Filter the cart template path to use cart.php in this plugin instead of the one in WooCommerce.
 *
 * @param string $template      Default template file path.
 * @param string $template_name Template file slug.
 * @param string $template_path Template file name.
 *
 * @return string The new Template file path.
 */
function intercept_wc_template( $template, $template_name, $template_path ) {

	if ( 'cart.php' === basename( $template ) ) {
		$template = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'woocommerce/cart/cart.php';
	}

	return $template;

}

Opción overriding varios archivos específico (ejemplo: cart.php y form-billing.php) Woocommerce:

add_filter( 'woocommerce_locate_template', 'intercept_wc_template', 10, 3 );
/**
 * Filter the cart template path to use cart.php in this plugin instead of the one in WooCommerce.
 *
 * @param string $template      Default template file path.
 * @param string $template_name Template file slug.
 * @param string $template_path Template file name.
 *
 * @return string The new Template file path.
 */
function intercept_wc_template( $template, $template_name, $template_path ) {

	if ( 'cart.php' === basename( $template ) ) {
		$template = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'woocommerce/cart/cart.php';
	} elseif ( 'form-billing.php' === basename( $template ) ) {
		$template = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'woocommerce/checkout/form-billing.php';
	}

	return $template;

}


Overriding otros plugin, ejemplo Nbdesigner

// Override templates NBdesigner web-to-print-online-designer
// ------------------------------------------------------------------------------------------------------ //

add_filter( 'nbdesigner_locate_template', 'intercept_nbdesigner_template', 10, 3 );
/**
 * Filter the cart template path to use cart.php in this plugin instead of the one in WooCommerce.
 *
 * @param string $template      Default template file path.
 * @param string $template_name Template file slug.
 * @param string $template_path Template file name.
 *
 * @return string The new Template file path.
 */
function intercept_nbdesigner_template( $template, $template_name, $template_path ) {

	$template_directory = trailingslashit( plugin_dir_path( __FILE__ ) ) . 'web-to-print-online-designer/';
	$path = $template_directory . $template_name;

	return file_exists( $path ) ? $path : $template;

}

Fuente:

https://wpdevdesign.com/how-to-override-woocommerce-templates-using-a-custom-functionality-plugin/

https://wpdevdesign.com/overriding-plugin-templates-in-oxygen/