wordpress - WooCommerce:如何找到我为禁用“添加到购物车”功能而修改的一段代码?
问题描述
我在 WooCommerce 中创建了一个网上商店。客户想避开原来的网店,所以我做了一个表格让客户订购产品。我不记得如何或在哪里修改了一个 PHP 文件以禁用“添加到购物车”功能。幸运的是,我有原始的主题文件,但害怕破坏一些东西。你们能帮帮我吗?
我试图检查我的 CSS,看看我是否在那里禁用了它,但它不在那里。另外,检查了function.php
文件,但我不记得我更改了什么。
我需要像最初一样回滚网店。再次使用其添加到购物车按钮。
请看一下代码:
woocommerce.php
<?php
/**
* Plugin Name: WooCommerce
* Plugin URI: https://woocommerce.com/
* Description: An eCommerce toolkit that helps you sell anything. Beautifully.
* Version: 3.5.4
* Author: Automattic
* Author URI: https://woocommerce.com
* Text Domain: woocommerce
* Domain Path: /i18n/languages/
*
* @package WooCommerce
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// Define WC_PLUGIN_FILE.
if ( ! defined( 'WC_PLUGIN_FILE' ) ) {
define( 'WC_PLUGIN_FILE', __FILE__ );
}
// Include the main WooCommerce class.
if ( ! class_exists( 'WooCommerce' ) ) {
include_once dirname( __FILE__ ) . '/includes/class-woocommerce.php';
}
/**
* Main instance of WooCommerce.
*
* Returns the main instance of WC to prevent the need to use globals.
*
* @since 2.1
* @return WooCommerce
*/
function wc() {
return WooCommerce::instance();
}
// Global for backwards compatibility.
$GLOBALS['woocommerce'] = wc();
函数.php
<?php
/* Load child theme stylesheet */
function amourchild_theme_style() {
wp_enqueue_style( 'amourparent-theme-style', get_template_directory_uri() . '/css/style.css' );
wp_enqueue_style( 'amourchild-childtheme-style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'amourchild_theme_style' , 10);
/* Insert custom functions below */
add_filter( 'woocommerce_is_purchasable', true );
/**
* @snippet Adds prefix and/or suffix to WooCommerce Prices (conditionally per category)
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @source https://businessbloomer.com/?p=472
* @author Rodolfo Melogli
* @compatible WooCommerce 2.4.7
*/
add_filter( 'woocommerce_get_price_html', 'bbloomer_price_prefix_suffix', 100, 2 );
function bbloomer_price_prefix_suffix( $price, $product ) {
// change 'audio' with your the category slug
if ( has_term( 'everyday-bouquets', 'product_cat' ) ) {
$price = 'From ' . $price . '';
}
if ( has_term( 'everyday-bouquets', 'product_cat' ) ) {
$product_price = 'From ' . $product_price . '';
}
if ( has_term( 'designers-choice', 'product_cat' ) ) {
$price = 'From ' . $price . '';
}
// no need to put the else! $price will stay the same
return apply_filters( 'woocommerce_get_price', $price );
}
/**
* Change currency display in WooCommerce
* Put this in your functions.php file
*
*/
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'USD': $currency_symbol = 'US$ '; break;
}
return $currency_symbol;
}
add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' );
/**
* Hide Product Cateories from targetted pages in WooCommerce
* @link https://gist.github.com/stuartduff/bd149e81d80291a16d4d3968e68eb9f8#file-wc-exclude-product-category-from-shop-page-php
*
*/
function prefix_custom_pre_get_posts_query( $q ) {
if( is_shop() || is_page(‘my-shop-page’) ) { // set conditions here
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'romance' ), // set product categories here
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
}
解决方案
幸运的是,我有原始的主题文件,但害怕破坏一些东西。你们能帮帮我吗?
这是一个很好的起点。
我会将原始主题文件与当前主题文件进行比较,看看我做了哪些更改。您可以通过文本编辑器或通过 Internet 上免费提供的特殊实用程序来完成此操作。
免责声明:由于我使用的是 Windows 操作系统,因此以下说明对 Windows 操作系统有效,但相同的程序可用于任何操作系统
如果我处于这种情况,我会这样做:
- 在我的本地机器上创建一个新文件夹Test,我可以在其中保存原始主题文件和当前主题文件。
- 将当前主题文件夹及其所有文件下载到Test文件夹。假设当前主题文件夹名称是current-theme。
- 将原始主题文件夹及其所有文件复制到Test文件夹。假设原始主题文件夹名称为original-theme。
- 下载并安装WinMerge。WinMerge 是用于 Windows 的开源差异和合并工具。
- 安装后,进入Test文件夹。
- 选择两个文件夹,即current-theme和original-theme。
- 右键单击并选择 WinMerge。
- 它将弹出WinMerge 文件夹比较视图。关注比较结果列,您可以在其中找到有差异的文件。
- 在 *Comparison result** 列中具有不同文本文件的文件上按 Enter 键。
- 它将在新选项卡中打开所选文件。在这里,您可以看到用颜色代码突出显示的两个文件中的所有差异。
现在,您可以在知道之前所做的更改后恢复到原始文件。
WinMerge 的快速浏览在一页中描述了功能和选项。
推荐阅读
- angular - 角度单选按钮与模型不同步
- javascript - 将 File Reader API 中的值添加到数组
- vb.net - VB.Net | Crystal Report:如何避免 Crystal Report 询问数据库登录
- bash - Bash:将变量存储在字符串中以便稍后解析
- hibernate - hibernate enableExtendedEnhancement 到底是做什么的?
- c++ - CPP:尝试将数据向量解析为 json 对象时获取 json.exception.type_error.302
- database - Mongoose:嵌套级别的多个填充
- objective-c - 词法或预处理器问题:将 Cocos2D 导出为 iOS 框架
- c# - EF Core:无法为具有通用 StartsWith() 表达式的嵌套列表翻译 LINQ 表达式
- r - 按变量过滤数据帧并输出为闪亮的表格