[go: up one dir, main page]

0% found this document useful (0 votes)
34 views8 pages

Func

The document contains PHP code that modifies WooCommerce functionality and templates. It adds custom product tabs, modifies text strings, and changes default WooCommerce behaviors like removing tabs and altering "Add to Cart" text. The code also includes functions for modifying templates and translating text for the WooCommerce plugin.

Uploaded by

Manuel P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views8 pages

Func

The document contains PHP code that modifies WooCommerce functionality and templates. It adds custom product tabs, modifies text strings, and changes default WooCommerce behaviors like removing tabs and altering "Add to Cart" text. The code also includes functions for modifying templates and translating text for the WooCommerce plugin.

Uploaded by

Manuel P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

<?

php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION


// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
function chld_thm_cfg_locale_css( $uri ){
if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() .
'/rtl.css' ) )
$uri = get_template_directory_uri() . '/rtl.css';
return $uri;
}
endif;
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );

if ( !function_exists( 'child_theme_configurator_css' ) ):
function child_theme_configurator_css() {
wp_enqueue_style( 'chld_thm_cfg_child',
trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'astra-
theme-css','astra-menu-animation','woocommerce-layout','woocommerce-
smallscreen','woocommerce-general' ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 10 );

//Este codigo los pege yo (molo) para cambiar textos en la pagina de finalizar
compra
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');

function translate_text($translated) {

$translated = str_ireplace('Facturación y envío', 'Detalles de envío',


$translated);
// original $translated = str_ireplace('TEXTO QUE NO QUIERO', 'TEXTO QUE SÍ
QUIERO', $translated);

return $translated;
}

/** Molo Los 3 proximos Tabs fueron costumizados. Se debe modificar el nombre la
funcion woo_new_product_tab para cada tab.
* Al igual que la funcion woo_new_product_tab_content()**/

/**
* Add a custom product data tab
**/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab_tr' );
function woo_new_product_tab_tr( $tabs ) {

// Adds the new tab

$tabs['tabla-raciones_tab'] = array(
'title' => __( 'Tabla de Raciones', 'woocommerce' ),
'priority' => 52,
'callback' => 'woo_new_product_tab_content_tr'
);

return $tabs;

}
function woo_new_product_tab_content_tr() {

// The new tab content

echo '<h2>Tabla de Raciones Diarias</h2>';


echo get_post_meta( get_the_ID(), 'tabla-raciones', true );

//echo '<p>Here\'s your new product tab.</p>';

/** Add a custom product data tab


**/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {

// Adds the new tab

$tabs['ingredientes_tab'] = array(
'title' => __( 'Ingredientes', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);

return $tabs;

}
function woo_new_product_tab_content() {

// The new tab content

echo '<h2>Ingredientes</h2>';
echo get_post_meta( get_the_ID(), 'ingredientes', true );

//echo '<p>Here\'s your new product tab.</p>';

/**
* Add a custom product data tab
**/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab_ag' );
function woo_new_product_tab_ag( $tabs ) {

// Adds the new tab

$tabs['analisis-garantizado_tab'] = array(
'title' => __( 'Analisis Garantizado', 'woocommerce' ),
'priority' => 51,
'callback' => 'woo_new_product_tab_content_ag'
);

return $tabs;

}
function woo_new_product_tab_content_ag() {

// The new tab content

echo '<h2>Analísis Garantizado</h2>';


echo get_post_meta( get_the_ID(), 'analisis-garantizado', true );

//echo '<p>Here\'s your new product tab.</p>';

/**
* Add a custom product data tab
**/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab_ia' );
function woo_new_product_tab_ia( $tabs ) {

// Adds the new tab

$tabs['informacion-adicional_tab'] = array(
'title' => __( 'Información Adicional', 'woocommerce' ),
'priority' => 49,
'callback' => 'woo_new_product_tab_content_ia'
);

return $tabs;

}
function woo_new_product_tab_content_ia() {

// The new tab content

echo '<h2>Información Adicional</h2>';


echo get_post_meta( get_the_ID(), 'informacion-adicional', true );

//echo '<p>Here\'s your new product tab.</p>';

// Molo este codigo, elimina el tab additional information que viene por defecto en
woocomerce
//Quitar pestaña de additional_information
add_filter( 'woocommerce_product_tabs', 'ayudawp_remove_description_tab', 50 );
function ayudawp_remove_description_tab( $tabs ) {
unset( $tabs['additional_information'] );
return $tabs;
}
/**
* Customize product data tabs
*/
/**add_filter( 'woocommerce_product_tabs', 'woo_custom_description_tab', 98 );
function woo_custom_description_tab( $tabs ) {

$tabs['description']['callback'] = 'woo_custom_description_tab_content';
// Custom description callback

return $tabs;
}

function woo_custom_description_tab_content() {
echo '<h2>Custom Description</h2>';
echo '<p>Here\'s a custom description</p>';
}*/

/** El cogido YIKES se puede borrar, no sirve para lo que necesito


*Molo este codigo es para poder importar custom tabs con la funcion de woocommerce
*/
/**
* Register the 'Custom Tab' column in the importer.
*
* @param array $options
* @return array $options
*/
/**function add_column_to_importer($options)
{
// column slug => column name
$options['yikes_custom_tabs'] = 'Custom Tabs';

return $options;
}
add_filter('woocommerce_csv_product_import_mapping_options',
'add_column_to_importer');

/**
* Add automatic mapping support for 'Custom Tabs'.
* This will automatically select the correct mapping for columns named 'Custom
Tabs'.
*
* @param array $columns
* @return array $columns

function add_column_to_mapping_screen($columns)
{
// potential column name => column slug
$columns['Custom Tabs'] = 'yikes_custom_tabs';

return $columns;
}
add_filter('woocommerce_csv_product_import_mapping_default_columns',
'add_column_to_mapping_screen');**/
/**
* Process the data read from the CSV file
* This just saves the decoded JSON in meta data, but you can do anything you want
here with the data.
*
* @param WC_Product $object - Product being imported or updated.
* @param array $data - CSV data read for the product.
* @return WC_Product $object
*/
/**function process_import($object, $data)
{
if (!empty($data['yikes_custom_tabs'])) {
$arr = json_decode($data['yikes_custom_tabs'], true);
$object->update_meta_data('yikes_woo_products_tabs', $arr);
}

return $object;
}
add_filter('woocommerce_product_import_pre_insert_product_object',
'process_import', 10, 2);**/

//Modificar texto del botón Añadir al carrito

/**function custom_woocommerce_product_add_to_cart_text() {

global $product;
$product_type = $product->product_type;

switch ( $product_type ) {
case 'external':
return __( 'Ir', 'woocommerce' );
break;
case 'grouped':
return __( 'Ver detalles', 'woocommerce' );
break;
case 'simple':
return __( 'Al Carrito', 'woocommerce' );
break;
case 'variable':
return __( 'Ver opciones', 'woocommerce' );
break;
default:
return __( 'Ver detalles', 'woocommerce' );
}

add_filter( 'woocommerce_product_add_to_cart_text' ,
'custom_woocommerce_product_add_to_cart_text' );**/

/**
*Molo, Este codigo es para cambiar el texto "Sin Stock" por "Todo Vendido"
*/

/** Para la pagina de productos */


add_filter( 'astra_woo_shop_out_of_stock_string', 'out_of_stock_callback' );
function out_of_stock_callback( $title ) {
return 'VENDIDO: Pincha para ver alternativas';
}

/** Para la pagina del producto individual */

add_filter( 'woocommerce_get_availability', 'change_out_of_stock_text_woocommerce',


1, 2 );
function change_out_of_stock_text_woocommerce( $availability, $product_to_check ) {
// Change Out of Stock Text
if ( ! $product_to_check->is_in_stock() ) {
$availability['availability'] = __('VENDIDO: Ver abajo Productos Relacionados',
'woocommerce');
}
return $availability;
}

/**
* Cambio de textos en WooCommerce/WordPress
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Al Carrito' :
$translated_text = __( 'Agregalo', 'woocommerce' );
break;
case 'Añadir al carrito' :
$translated_text = __( 'Añadelo al Carrito', 'woocommerce' );
break;
case 'Productos relacionados' :
$translated_text = __( 'Quizás te interesen estos excelentes
productos', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );

/*
* Molo con esta funcion se cambia el texto Availability por Disponibilidad, en las
paginas de productos solos.
*/

function astra_woo_product_in_stock( $markup, $product ) {

if ( is_product() ) {
$product_avail = $product->get_availability();
$stock_quantity = $product->get_stock_quantity();
$availability = $product_avail['availability'];
$avail_class = $product_avail['class'];
if ( ! empty( $availability ) && $stock_quantity ) {
ob_start();
?>
<p class="ast-stock-detail">
<span class="ast-stock-avail"><?php
esc_html_e( 'Disponibilidad:', 'astra' ); ?></span>
<span class="stock <?php echo
esc_html( $avail_class ); ?>"><?php echo esc_html( $availability ); ?></span>
</p>
<?php
$markup = ob_get_clean();
}
}

return $markup;
}

/*
* Molo esta funcion Adding Alphabetical sorting option to shop and product
settings pages
*/

function alphabetical_shop_ordering( $sort_args ) {


$orderby_value = isset( $_GET['orderby'] ) ?
woocommerce_clean( $_GET['orderby'] ) :
apply_filters( 'woocommerce_default_catalog_orderby',
get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'alphabetical_az' == $orderby_value ) {
$sort_args['orderby'] = 'title';
$sort_args['order'] = 'asc';
$sort_args['meta_key'] = '';
}
if ( 'alphabetical_za' == $orderby_value ) { // molo: modifique esta funcion
para ir de A a Z y de Z a A
$sort_args['orderby'] = 'title';
$sort_args['order'] = 'des';
$sort_args['meta_key'] = '';
}

return $sort_args;
}
add_filter( 'woocommerce_get_catalog_ordering_args',
'alphabetical_shop_ordering' );

function custom_wc_catalog_orderby( $sortby ) {


$sortby['alphabetical_za'] = 'Ordena por Nombre: Alfabeticamente Z-A';
$sortby['alphabetical_az'] = 'Ordena por Nombre: Alfabeticamente A-Z';// PUEDES
PONER EL TEXTO QUE QUIERAS
return $sortby;
}
add_filter( 'woocommerce_default_catalog_orderby_options',
'custom_wc_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_wc_catalog_orderby' );

/*
* Molo esta funcion cambia el texto de ALT por el nombre del titulo de la imagen.
*/

add_filter('wp_get_attachment_image_attributes',
'change_attachement_image_attributes', 20, 2);
function change_attachement_image_attributes( $attr, $attachment ){
// Get post parent
$parent = get_post_field( 'post_parent', $attachment);

// Get post type to check if it's product

$type = get_post_field( 'post_type', $parent);


if( $type != 'product' ){
return $attr;
}

/// Get title


$title = get_post_field( 'post_title', $parent);

if( $attr['alt'] == ''){


$attr['alt'] = $title;
$attr['title'] = $title;
}

return $attr;
}

You might also like